The max matrix of two matrices

43 次查看(过去 30 天)
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

采纳的回答

Kelly Kearney
Kelly Kearney 2014-8-7

更多回答(2 个)

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

Praveen Pawar
Praveen Pawar 2018-3-6
编辑:Praveen Pawar 2018-3-6
If I have two vectors of dimension (X,1) and (Y,1). I want to compare (x1,y1), (x2,y2) and so on and store the larger number in another vector. How to do this?

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by