Alon Shmiel
Alon Shmiel

Reputation: 7121

matlab try to write the max function

I'm trying to write the max function of matlab:

B = max(A,B);

Is it correct?

for i=1:size(A,1)
    for j=1:size(A,2)
       if A(i,j) > B(i,j)
         B(i,j) = A(i,j);
       end
    end
end

thank you!

Upvotes: 0

Views: 961

Answers (1)

Gunther Struyf
Gunther Struyf

Reputation: 11168

if you mean that B = max(A,B) should output a matrix containing at each index (i,j) the largest of either A(i,j) or B(i,j), then yes, it is correct (if you supply it with two-dimensional matrices A and B with size(A)>=size(B) )

The standard max function however does not exactly work like that. For example it can also handle higher dimensional matrix input, you can specify along which dimension you want to calculate maximum,...

Upvotes: 2

Related Questions