Clear Filters
Clear Filters

how to find the row wise maximum and minimum values of equal sized matrices in a cell array

2 views (last 30 days)
Hi, I have a cell array containing 2 equal sized matrices a=[1 2 3;3 4 5]; b=[5 4 6;7 6 9]; c={a,b}; now i need to find the maximum and minimum values among both matrices a and b row wise using cell array operations. example : max(a(1,:) and b(1,:))=6 max(a(2,:) and b(2,:))=9 min(a(1,:) and b(1,:))=1 min(a(2,:) and b(2,:))=3 I know how to do with matrix operations by matrix concatenation. But how to do this using cell array operations without writing many lines of code.

Accepted Answer

Guillaume
Guillaume on 3 Feb 2017
Concatenate the matrices horizontally, get the max or min of this along the rows:
a=[1 2 3;3 4 5]; b=[5 4 6;7 6 9]; c={a,b};
max([c{:}], [], 2) %concatenation + max on rows
min([c{:}], [], 2) %concatenation + min on rows

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!