Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
position and max of my results

Subject: position and max of my results

From: nick

Date: 3 Dec, 2010 22:09:05

Message: 1 of 7

Hi,
I would like your help in this 'theoretical' problem.
I wrote this code and i have this results
>> x=0:0.5:5;
>> result=exppdf(x,1)

result =

  Columns 1 through 7

    1.0000 0.6065 0.3679 0.2231 0.1353 0.0821 0.0498

  Columns 8 through 11

    0.0302 0.0183 0.0111 0.0067

I have also a variable gamma=0.4(for example).I would like when result>gamma then to saw me the the first bigger value of gamma and the position of this value.
In my example:
gamma=0.4;
the first bigger value is 0.6065 and the position is 2.
other example:
gamma=0.1;
the first bigger value is 0.1353 and the position is 5.

How can i do this this?
I hope you understand my problem..Thanks for your help.

Subject: position and max of my results

From: Walter Roberson

Date: 3 Dec, 2010 22:19:04

Message: 2 of 7

On 10-12-03 04:09 PM, nick wrote:

> I would like your help in this 'theoretical' problem.
> I wrote this code and i have this results
>>> x=0:0.5:5;
>>> result=exppdf(x,1)
>
> result =
>
> Columns 1 through 7
>
> 1.0000 0.6065 0.3679 0.2231 0.1353 0.0821 0.0498
>
> Columns 8 through 11
>
> 0.0302 0.0183 0.0111 0.0067
>
> I have also a variable gamma=0.4(for example).I would like when
> result>gamma then to saw me the the first bigger value of gamma and the
> position of this value.
> In my example:
> gamma=0.4;
> the first bigger value is 0.6065 and the position is 2.
> other example:
> gamma=0.1;
> the first bigger value is 0.1353 and the position is 5.
>
> How can i do this this?

index = find(result>gamma,1,'first');
biggergamma = result(index);

Subject: position and max of my results

From: Sean de

Date: 3 Dec, 2010 22:21:07

Message: 3 of 7

"nick " <powerman1985@hotmail.com> wrote in message <idbpq1$mrf$1@fred.mathworks.com>...
> Hi,
> I would like your help in this 'theoretical' problem.
> I wrote this code and i have this results
> >> x=0:0.5:5;
> >> result=exppdf(x,1)
>
> result =
>
> Columns 1 through 7
>
> 1.0000 0.6065 0.3679 0.2231 0.1353 0.0821 0.0498
>
> Columns 8 through 11
>
> 0.0302 0.0183 0.0111 0.0067
>
> I have also a variable gamma=0.4(for example).I would like when result>gamma then to saw me the the first bigger value of gamma and the position of this value.
> In my example:
> gamma=0.4;
> the first bigger value is 0.6065 and the position is 2.
> other example:
> gamma=0.1;
> the first bigger value is 0.1353 and the position is 5.
>
> How can i do this this?
> I hope you understand my problem..Thanks for your help.

g = .1; %don't use gamma because it's a built-in function
max(find(result>.g))

Subject: position and max of my results

From: nick

Date: 4 Dec, 2010 14:49:05

Message: 4 of 7

"Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <idbqgj$apb$1@fred.mathworks.com>...
> "nick " <powerman1985@hotmail.com> wrote in message <idbpq1$mrf$1@fred.mathworks.com>...
> > Hi,
> > I would like your help in this 'theoretical' problem.
> > I wrote this code and i have this results
> > >> x=0:0.5:5;
> > >> result=exppdf(x,1)
> >
> > result =
> >
> > Columns 1 through 7
> >
> > 1.0000 0.6065 0.3679 0.2231 0.1353 0.0821 0.0498
> >
> > Columns 8 through 11
> >
> > 0.0302 0.0183 0.0111 0.0067
> >
> > I have also a variable gamma=0.4(for example).I would like when result>gamma then to saw me the the first bigger value of gamma and the position of this value.
> > In my example:
> > gamma=0.4;
> > the first bigger value is 0.6065 and the position is 2.
> > other example:
> > gamma=0.1;
> > the first bigger value is 0.1353 and the position is 5.
> >
> > How can i do this this?
> > I hope you understand my problem..Thanks for your help.
>
> g = .1; %don't use gamma because it's a built-in function
> max(find(result>.g))


Thank you for your help!one more question.
I write this and gave me the position.
g = .1;
max(find(result>g))

Is there a way to print that 'the max number is 0.6065 and the position is 2'?
Where 0.6065 and 2 are my examples values.Something like a pointer to update every time these 2 values?
Thank you.

Subject: position and max of my results

From: ImageAnalyst

Date: 4 Dec, 2010 15:01:07

Message: 5 of 7

Building on Walter's solution:

% result = rand(10,1) - 1 % test that fails. Nothing > 0.1
result = rand(10,1) % test that works.
g = 0.1;
index = find(result>g,1,'first');
if ~isempty(index)
biggergamma = result(index);
fprintf(1, 'The max number is %f and occurs at position %d\n',...
biggergamma, index);
else
fprintf(1, 'There is no number bigger than %f\n', g);
end

Subject: position and max of my results

From: nick

Date: 4 Dec, 2010 18:10:07

Message: 6 of 7

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <20aa7ec3-5552-4ca0-831e-0cbbb2b76eec@a17g2000yql.googlegroups.com>...
> Building on Walter's solution:
>
> % result = rand(10,1) - 1 % test that fails. Nothing > 0.1
> result = rand(10,1) % test that works.
> g = 0.1;
> index = find(result>g,1,'first');
> if ~isempty(index)
> biggergamma = result(index);
> fprintf(1, 'The max number is %f and occurs at position %d\n',...
> biggergamma, index);
> else
> fprintf(1, 'There is no number bigger than %f\n', g);
> end

Thank you very much for your help.I would like to ask you something else.
If i have these results
result =

    1.0000 0.3679 0.1353 0.0498 0.0183 0.0067
and i give for example
b=0.1;
I would like when b finds the first bigger value to stop and to give this value.
In this example 1.000 is bigger and must stop there.
other example:
if the result was
0.001 0.023 0.3 0.2 0.048
then 0.3 is the first bigger value and the programm stops there.
Generally i would like to compare b with the results.And when i found the first bigger to stop and give me this number.

Subject: position and max of my results

From: ImageAnalyst

Date: 4 Dec, 2010 18:49:34

Message: 7 of 7

numberToStopAt = find(result>b, 1, 'first');

Tags for this Thread

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.

Contact us