How to find a maximum number not considered minus sign?

30 次查看(过去 30 天)
Sir,
I want find the maximum number in the given array.
But, I am not considered negative sign.
for example, a=[4, 3, -8],
output is = -8. Because 8 is the maximum number.
how I get this output.
thank you.

采纳的回答

Andrei Bobrov
Andrei Bobrov 2014-7-17
a = [4, 3, -8];
[~,ii] = max(abs(a));
out = a(ii);

更多回答(1 个)

Matz Johansson Bergström
It sounds like you want to find the max absolute value of a vector. This can be accomplished simply by taking the absolute value and remember the index to that value and picking it out:
a = [1,4,5,-8,3];
[val, ind] = max(abs(a));
a(ind)

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by