How do i determine the highest values of my for loop?

2 次查看(过去 30 天)
for x = 3:0.2:9
y=(cos(x+1)/(pi*x-1));
disp(['x = ',num2str(x)])
disp(['y = ',num2str(y)])
end
I need to find the highest values (x and y) of the results of this for loop, which i know are "x = 9" and "y = 0.065282" by looking into the results.
But i can't think of a command that'll do it without the need of eye analysis...
Thanks in advance.

采纳的回答

KSSV
KSSV 2022-10-5
x = 3:0.2:9 ;
y=(cos(x+1)./(pi*x-1));
[val,idx] = max(y) ;
[x(idx) y(idx)]
ans = 1×2
5.0000 0.0653

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by