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?
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"?
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
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.
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:
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]);
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>...
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.