Clear Filters
Clear Filters

Ho to do

1 view (last 30 days)
Sukumar Palo
Sukumar Palo on 24 Feb 2011
hi
I have an array of 50 data points as 1X50. I want to find out 3 points prior to the maximum value in the array.
eg: the maximum value is on 27th position I want solution that will return the 24th position in the array
how to do it
thanx in advance
  2 Comments
Robert Cumming
Robert Cumming on 24 Feb 2011
what have you tried?
Jan
Jan on 24 Feb 2011
You have posted the same question in CSSM. Rossposting confuses the people, who want to help you.

Sign in to comment.

Answers (1)

Jan
Jan on 24 Feb 2011
Have you read the help text of MAX?
x = rand(1, 50);
[maxValue, maxIndex] = max(x);
maxIndexMinus3 = maxIndex - 3;
Most likely this might cause troubles if the first element is the maximum. So perhaps you want this:
maxIndexMinus3 = max(1, maxIndex - 3);
  3 Comments
Robert Cumming
Robert Cumming on 24 Feb 2011
you still need to find where the max is. Jan has given you the answer - have you tried it?
Jan
Jan on 24 Feb 2011
What exactly are the inputs of your problem? Do you know the index of the maximum initially? Then use just the last line I've posted. If you don't now the index of the maximum, the function has to find it of course.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!