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

61 views (last 30 days)
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 ??

Answers (4)

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

Andreas Goser
Andreas Goser on 17 May 2013
Not sure if
max(abs())
counts as single command for you...
  2 Comments
Andreas Goser
Andreas Goser on 17 May 2013
"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.

Sign in to comment.


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

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

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!