Taking the median of the same matrix index over a series of matrices
1 view (last 30 days)
Show older comments
I am trying to calculate the median of each matrix index over multiple matrices. For example:
A = [1 2 3; 4 5 6; 7 8 9];
B = [9 8 7; 6 5 4; 3 2 1];
C = [3 3 5; 6 7 4; 8 6 5];
All are 3x3 matrices and what I would like to do is to calculate the median of A(i,j), B(i,j), and C(i,j).
What I was thinking is to convert all matrices into an array, and compose a large matrix out of the strings. Like this:
A = A'; A = A(:)'
B = B'; B = B(:)'
C = C'; C = C(:)'
X = [A; B; C];
Med = median(X,'c');
Is there is a better way to do this? I am trying to do this to a series of 2048x2048 images and I would like to avoid unnecessarily large matrix operations.
Thanks in advance!
0 Comments
Accepted Answer
Geoff Hayes
on 17 Oct 2015
D = cat(3,A,B,C);
where D(:,:,1) == A, D(:,:,2) == B and D(:,:,3) == C.
median(D,3)
which returns
3 3 5
6 5 4
7 6 5
which should be the median for A(i,j), B(i,j), and C(i,j).
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!