using find-command to find max or min value

조회 수: 3 (최근 30일)
Moustafa Abedel Fattah
Moustafa Abedel Fattah 2022년 6월 26일
댓글: Moustafa Abedel Fattah 2022년 6월 28일
Please I need your help to estimate the value of min or max of abs(Y) and its corresponding (X) for attached curve (X versus X ) using (find)-command. In addition want plot a line of corresponding (X) and (Y).
Thanks in advance for all.
Best Regards;
  댓글 수: 1
Moustafa Abedel Fattah
Moustafa Abedel Fattah 2022년 6월 26일
Thanks a lot for your quick response as usual. It is works very good and I will more appreciate if you solve it also with (find) command.
Thanks in advance
Best Regards;

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2022년 6월 26일
This is relatively straightforward. Use max with two outputs:
x = 0:13;
y = randi(25,1,14)/100;
[ymax,idx] = max(y)
ymax = 0.2400
idx = 13
figure
plot(x, y)
hold on
plot([1 1]*x(idx), [min(ylim) ymax], '-r')
plot([0 x(idx)], [1 1]*ymax, '-r')
hold off
grid
Experiment with your data.
.
  댓글 수: 1
Star Strider
Star Strider 2022년 6월 27일
As always, my pleasure!
Using find is straghtforward —
x = 0:13;
y = randi(25,1,14)/100;
idx = find(y == max(y))
idx = 10
figure
plot(x, y)
hold on
plot([1 1]*x(idx), [min(ylim) y(idx)], '-r')
plot([0 x(idx)], [1 1]*y(idx), '-r')
hold off
grid
That requires essentially the same code.
.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2022년 6월 26일
I prefer using the find function in combination to find max and min locations. The reason being if the max occurs at more than one location, max only gives you the location of the first one. I've asked them for many, many years to return the index(es) of all max in the vactor.
y = [1 3 2 3 0] % Max at index 2 and 4
y = 1×5
1 3 2 3 0
[maxValue, indexes] = max(y) % Only gives you the one at index 2 not at 4.
maxValue = 3
indexes = 2

카테고리

Help CenterFile Exchange에서 Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by