The max matrix of two matrices

9 views (last 30 days)
S. David
S. David on 7 Aug 2014
Commented: Ben11 on 7 Aug 2014
Hello,
If I have two N-by-N matrices A and B, how can I find the N-by-by matrix C such that its (m,n)th element is the max of the (m,n)th element in A and the (m,n)th element in B?
Note: I don't want to use a for loop because N is quiet large.
Thanks

Accepted Answer

Kelly Kearney
Kelly Kearney on 7 Aug 2014
C = max(A,B);
  1 Comment
Ben11
Ben11 on 7 Aug 2014
Nicely done I think I over-complicated this :)

Sign in to comment.

More Answers (1)

Ben11
Ben11 on 7 Aug 2014
Try this:
C = arrayfun(@(x,y) max(x(:),y(:)),A,B)

Tags

Community Treasure Hunt

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

Start Hunting!