Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: finding minium pts in a matrix

Subject: finding minium pts in a matrix

From: Ender

Date: 11 Jul, 2008 18:55:04

Message: 1 of 6

I have a matrix with 5 columns and n rows. I want to find
the minium number in column B before the numbers become
negative. Then I want to find the corresponding value in
the matrix in column D & E at the last positive number in
column B. How can I do this?

--Ender--

Subject: finding minium pts in a matrix

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 11 Jul, 2008 19:12:47

Message: 2 of 6

In article <g58aa8$lqr$1@fred.mathworks.com>, Ender <jr147@msstate.edu> wrote:
>I have a matrix with 5 columns and n rows. I want to find
>the minium number in column B before the numbers become
>negative. Then I want to find the corresponding value in
>the matrix in column D & E at the last positive number in
>column B. How can I do this?

What if the first number in the column is already negative?
What if the last positive number in column B is after the
numbers in that column went negative for awhile?
What if the last non-negative number in the column is 0? Then
does that 0 count as "the last positive number"?


minBeforeFirstNeg = min(Matrix(find(Matrix(:,2)<0,1)-1,2);
colsDEatLastPositive = Matrix(find(Matrix(:,2)>0,1,'last'),[4 5]);

In some combinations of circumstances the above can be optimized
a little; it depends on your answers to the questions.
--
  "Why does he stagger his mind with the mathematics of the sky?
  Once the question mark has arisen in the human brain the answer must
  be found, if it takes a hundred years. A thousand years."
                                              -- Walter Reisch

Subject: finding minium pts in a matrix

From: Ender

Date: 11 Jul, 2008 20:00:23

Message: 3 of 6

roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
message <g58bbf$b8p$1@canopus.cc.umanitoba.ca>...
> In article <g58aa8$lqr$1@fred.mathworks.com>, Ender
<jr147@msstate.edu> wrote:
> >I have a matrix with 5 columns and n rows. I want to
find
> >the minium number in column B before the numbers become
> >negative. Then I want to find the corresponding value
in
> >the matrix in column D & E at the last positive number
in
> >column B. How can I do this?
>
> > What if the last positive number in column B is after
the
> numbers in that column went negative for awhile?
> What if the last non-negative number in the column is 0?
Then
> does that 0 count as "the last positive number"?
>
>
> minBeforeFirstNeg = min(Matrix(find(Matrix(:,2)<0,1)-
1,2);
> colsDEatLastPositive = Matrix(find(Matrix(:,2)
>0,1,'last'),[4 5]);
>
> In some combinations of circumstances the above can be
optimized
> a little; it depends on your answers to the questions.
> --
> "Why does he stagger his mind with the mathematics of
the sky?
> Once the question mark has arisen in the human brain
the answer must
> be found, if it takes a hundred years. A thousand
years."
> -- Walter
Reisch


To answer your question:

"What if the first number in the column is already
negative?"

This is not possible because I have graphed the data. The
graph moves through 0 in the x-axis then has a negative
minimum point then goes back through 0 again (x-axis).

"What if the last positive number in column B is after the
numbers in that column went negative for awhile?"

This does happen, but I am only interested in the instant
when the data first becomes 0.


What if the last non-negative number in the column is 0?
Then does that 0 count as "the last positive number"?

The data will never be exactly 0. I want the last positive
number before the data becomes negative.


I think this will help narrow down my search criteria.

--Ender--


Subject: finding minium pts in a matrix

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 11 Jul, 2008 20:25:11

Message: 4 of 6

In article <g58e4n$141$1@fred.mathworks.com>, Ender <jr147@msstate.edu> wrote:
>roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
>message <g58bbf$b8p$1@canopus.cc.umanitoba.ca>...
>> In article <g58aa8$lqr$1@fred.mathworks.com>, Ender
><jr147@msstate.edu> wrote:
>> >I have a matrix with 5 columns and n rows. I want to
>find
>> >the minium number in column B before the numbers become
>> >negative. Then I want to find the corresponding value
>in
>> >the matrix in column D & E at the last positive number
>in
>> >column B. How can I do this?


>"What if the last positive number in column B is after the
>numbers in that column went negative for awhile?"

>This does happen, but I am only interested in the instant
>when the data first becomes 0.


Okay, then, a small modification of what I had before:

OLD:
minBeforeFirstNeg = min(Matrix(find(Matrix(:,2)<0,1)-1,2);
colsDEatLastPositive = Matrix(find(Matrix(:,2)>0,1,'last'),[4 5]);

NEW:

numLeadingNonneg = find( Matrix(:,2)<0, 1) - 1;
minBBeforeFirstNeg = min( Matrix(1:numLeadingNonneg,2) );
colsDEatLastPositive = Matrix(minBBeforeFirstNeg,[4 5]);

--
  "Do not wait for leaders. Do it alone, person to person."
                                              -- Mother Teresa

Subject: finding minium pts in a matrix

From: Ender

Date: 14 Jul, 2008 15:20:22

Message: 5 of 6

roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
message <g58fj7$hdv$1@canopus.cc.umanitoba.ca>...
> In article <g58e4n$141$1@fred.mathworks.com>, Ender
<jr147@msstate.edu> wrote:
> >roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
> >message <g58bbf$b8p$1@canopus.cc.umanitoba.ca>...
> >> In article <g58aa8$lqr$1@fred.mathworks.com>, Ender
> ><jr147@msstate.edu> wrote:
> >> >I have a matrix with 5 columns and n rows. I want to
> >find
> >> >the minium number in column B before the numbers
become
> >> >negative. Then I want to find the corresponding
value
> >in
> >> >the matrix in column D & E at the last positive
number
> >in
> >> >column B. How can I do this?
>
>
> >"What if the last positive number in column B is after
the
> >numbers in that column went negative for awhile?"
>
> >This does happen, but I am only interested in the
instant
> >when the data first becomes 0.
>
>
> Okay, then, a small modification of what I had before:
>
> OLD:
> minBeforeFirstNeg = min(Matrix(find(Matrix(:,2)<0,1)-
1,2);
> colsDEatLastPositive = Matrix(find(Matrix(:,2)
>0,1,'last'),[4 5]);
>
> NEW:
>
> numLeadingNonneg = find( Matrix(:,2)<0, 1) - 1;
> minBBeforeFirstNeg = min( Matrix(1:numLeadingNonneg,2) );
> colsDEatLastPositive = Matrix(minBBeforeFirstNeg,[4 5]);
>
> --
> "Do not wait for leaders. Do it alone, person to
person."
> -- Mother
Teresa



I am having trouble with the code. I put in the code you
suggested, but here is the error that I am getting. I am
not really sure what it means:

??? Subscript indices must either be real positive
integers or logicals.

Error in ==> Electric_Constants at 55
colsDEatLastPositive = JackR(minBBeforeFirstNeg,[4 5]);


--Ender--

Subject: finding minium pts in a matrix

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 14 Jul, 2008 16:16:53

Message: 6 of 6

In article <g5fqrm$dbo$1@fred.mathworks.com>, Ender <jr147@msstate.edu> wrote:
>roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
>message <g58fj7$hdv$1@canopus.cc.umanitoba.ca>...

>> numLeadingNonneg = find( Matrix(:,2)<0, 1) - 1;
>> minBBeforeFirstNeg = min( Matrix(1:numLeadingNonneg,2) );
>> colsDEatLastPositive = Matrix(minBBeforeFirstNeg,[4 5]);

>??? Subscript indices must either be real positive
>integers or logicals.

Opps, correction to my correction:

numLeadingNonneg = find( Matrix(:,2)<0, 1) - 1;
minBBeforeFirstNeg = min( Matrix(1:numLeadingNonneg,2) );
lastPosBeforeFirstNeg = find(Matrix(1:numLeadingNonneg,2)>0,1,'last');
colsDEatLastPositive = Matrix(lastPosBeforeFirstNeg,[4 5]);

--
  "To the modern spirt nothing is, or can be rightly known,
  except relatively and under conditions." -- Walter Pater

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics