Find max of matrix without using built in function.

16 views (last 30 days)
I want to find the "max(a)" without actually using the built in "max" function.
  2 Comments
Sean de Wolski
Sean de Wolski on 4 May 2011
We won't do your homework for you. What have you tried so far.

Sign in to comment.

Accepted Answer

Paulo Silva
Paulo Silva on 4 May 2011
mx=a(1);
for p=2:numel(a)
if a(p)>mx
mx=a(p);
end
end
mx %the maximum value
  3 Comments
Paulo Silva
Paulo Silva on 4 May 2011
The code isn't optimized on purpose, like Sean said "We won't do your homework for you"

Sign in to comment.

More Answers (2)

Sean de Wolski
Sean de Wolski on 4 May 2011
the_max = -min(-(a(:)))

Adrien Leygue
Adrien Leygue on 4 May 2011
The following code will extract the minimum over each column. No loop no max no min and of course not optimal. Feel free to adapt it to other purposes:
S = A((repmat(eye(size(A,1)),[1 size(A,1)]) *(kron(A,ones(size(A,1),1)) < kron(ones(size(A,1),1),A)))==0)'
A.

Community Treasure Hunt

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

Start Hunting!