finding the max number?

1 次查看(过去 30 天)
Ls
Ls 2021-9-12
回答: Chunru 2021-9-12
x=[1 3 5 7]
y=x^2+5
y=[6 14 30 54]
max(y)
how do i find x value corresponding to max(y)?

回答(1 个)

Chunru
Chunru 2021-9-12
x=[1 3 5 7]
x = 1×4
1 3 5 7
y=x.^2+5 % use .^ here
y = 1×4
6 14 30 54
[~, idx] = max(y) % idx the where y is the max
idx = 4
x(idx) % corresponding x
ans = 7
y(idx)
ans = 54

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

标签

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by