How to use max function in cell arrays or structures?

3 views (last 30 days)
I have a cell arrays:
.
.
how do i apply the
max function
to get the maximum 7x2 matrix value across all 3 matrices?
Example
g{1,1} = 1 2 3
2 4 5
5 3 2
g{1,2} = 2 4 1
1 7 2
1 1 2
g{1,3} = 2 2 2
3 1 2
4 8 1
So i will bring the the highest matrix such that
A = 2 4 3
3 7 5
5 8 2

Accepted Answer

Jan
Jan on 2 Nov 2014
g{1,1} = [1 2 3
2 4 5
5 3 2]
g{1,2} =[ 2 4 1
1 7 2
1 1 2]
g{1,3} =[ 2 2 2
3 1 2
4 8 1]
result = max(cat(3, g{:}), [], 3)
  1 Comment
hithere
hithere on 3 Nov 2014
hi.
will appreciate if you could explain?
what does the (3, g{:]), [], 3 means?
thanks

Sign in to comment.

More Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 2 Nov 2014
v={rand(7,2),rand(7,2),rand(7,2)}
a=cell2mat(v)
out=max(a(:))
  4 Comments
hithere
hithere on 2 Nov 2014
opps
i mean not only bringing out the highest value. but the highest 7x2 matrix.
g{1,1} = 1 2 3
2 4 5
5 3 2
g{1,2} = 2 4 1
1 7 2
1 1 2
g{1,3} = 2 2 2
3 1 2
4 8 1
So i will bring the the highest matrix such that
A = 2 4 3
3 7 5
5 8 2
Azzi Abdelmalek
Azzi Abdelmalek on 2 Nov 2014
g{1,1} = [1 2 3
2 4 5
5 3 2]
g{1,2} =[ 2 4 1
1 7 2
1 1 2]
g{1,3} =[ 2 2 2
3 1 2
4 8 1]
out=max(reshape(cell2mat(g),3,3,[]),[],3)

Sign in to comment.

Categories

Find more on Data Types in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!