필터 지우기
필터 지우기

Find max of matrix without using built in function.

조회 수: 3 (최근 30일)
Roland
Roland 2011년 5월 4일
I want to find the "max(a)" without actually using the built in "max" function.
  댓글 수: 2
Roland
Roland 2011년 5월 4일
I'm trying to do this with a for loop as test preparation.
Sean de Wolski
Sean de Wolski 2011년 5월 4일
We won't do your homework for you. What have you tried so far.

댓글을 달려면 로그인하십시오.

채택된 답변

Paulo Silva
Paulo Silva 2011년 5월 4일
mx=a(1);
for p=2:numel(a)
if a(p)>mx
mx=a(p);
end
end
mx %the maximum value
  댓글 수: 3
Paulo Silva
Paulo Silva 2011년 5월 4일
%code made here, not tested in matlab
mxc=zeros(1,size(a,2));
for n=1:size(a,2)
mx=a(1,n);
for p=2:size(a,1)
if a(p,n)>mx
mx=a(p,n);
end
end
mxc(n)=mx;
end
mxc %the maximum value per column
Paulo Silva
Paulo Silva 2011년 5월 4일
The code isn't optimized on purpose, like Sean said "We won't do your homework for you"

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Sean de Wolski
Sean de Wolski 2011년 5월 4일
the_max = -min(-(a(:)))
  댓글 수: 2
Roland
Roland 2011년 5월 4일
I need to use logical operators.
Sean de Wolski
Sean de Wolski 2011년 5월 4일
the_max = a(a==-min(-(a(:))))
There!

댓글을 달려면 로그인하십시오.


Adrien Leygue
Adrien Leygue 2011년 5월 4일
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.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by