is there any command to find a maximum value of a matrix containing negative numbers also ??

21 次查看(过去 30 天)
x =
-1 -1 -1 -1 0 -1 23 19
i need to find a maximum value for this. can i get a single line command ??

回答(4 个)

Iain
Iain 2013-6-6
No single line command, but
largest_val = (-min(x) < max(x))*(max(x)-min(x))+min(x);
is cheeky and it preserves the sign.

Jan
Jan 2013-6-6
编辑:Jan 2013-6-6
You need the "maximum value". Then there is no reason for ABS, but you can call simply:
result = max(x)

Andreas Goser
Andreas Goser 2013-5-17
Not sure if
max(abs())
counts as single command for you...
  2 个评论
Andreas Goser
Andreas Goser 2013-5-17
"I should not" because of a good technical reason or just because someone told you / this is part of a homework? I can think of sorting the values first and then take the largest of the (1) and (end) values.

请先登录,再进行评论。


Daniel Shub
Daniel Shub 2013-6-6
What about
sqrt(max(x(:).^2))

类别

Help CenterFile Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by