How to get the coordinates of my minimum and maximum value?
24 次查看(过去 30 天)
显示 更早的评论
for i=1:n
x=100*rand(1,i);
y=100*rand(1,i); end
d=sqrt((0-x).^2+(0-y).^2);
disp(d)
NP =(min(d)); %how to get coordinates of this
FP =(max(d)); %and this
plot(x,y,'b*')
hold on
how could i get the coordinates of the nearest point (NP) and farthest point (FP)?
1 个评论
Roger Stafford
2015-4-12
As you have written the for-loop, it is overwriting each x and y from 1 to n-1. You could just as well have written
x=100*rand(1,n);
y=100*rand(1,n);
without the for-loop. The result would be the same.
采纳的回答
Image Analyst
2015-4-12
Use the second return argument of max and min:
[minValue, indexOfMinValue = min(d);
[maxValue, indexOfMaxValue = max(d);
That essentially gives you [y, index]. To get x and y:
xMin = x(indexOfMinValue);
yMin = minValue;
xMax = x(indexOfMaxValue);
yMax = maxValue;
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!