Thread Subject: Calculating Median of multiple matrices

Subject: Calculating Median of multiple matrices

From: Subrat Swain

Date: 24 Nov, 2008 21:30:18

Message: 1 of 2

Hi all,
I want to find the median of a matrx in MATLAB and I need the appropriate code for it. For example my input matrix is given as
D = 0 2 6
      5 0 8 ---------------- Ist 3*3 matrix (A)
      7 4 0
      0 7 6
      5 0 1 --------------- 2nd 3*3 matrix (B)
      3 2 0
      0 9 10
      4 0 8 ------------- 3rd 3*3 matrix (C)
      3 6 0
The resulting median should be such that the first element of the 'A' matrix ,
(D(1,1) - 0) should get associated with the first element of B matrix, (D(4,1) - 0) and the first element of the C matrix, (D(7,1) - 0) and then the corresponding median should be found out between these 3 numbers. Similarly the median should be found out for the remaining elements of A,B and C matrices. My output median matrix should be the B matrix.

E = 0 7 6
       5 0 1
       3 2 0

I appreciate for the help.

Thanks and Regards,
Subrat Kumar Swain.

Subject: Calculating Median of multiple matrices

From: Ashish Uthama

Date: 24 Nov, 2008 21:51:00

Message: 2 of 2

On Mon, 24 Nov 2008 16:30:18 -0500, Subrat Swain
<swain.subrat01@gmail.com> wrote:

> Hi all,
> I want to find the median of a matrx in MATLAB and I need the
> appropriate code for it. For example my input matrix is given as
> D = 0 2 6
> 5 0 8 ---------------- Ist 3*3 matrix (A)
> 7 4 0
> 0 7 6
> 5 0 1 --------------- 2nd 3*3 matrix (B)
> 3 2 0
> 0 9 10
> 4 0 8 ------------- 3rd 3*3 matrix (C)
> 3 6 0
> The resulting median should be such that the first element of the 'A'
> matrix ,
> (D(1,1) - 0) should get associated with the first element of B matrix,
> (D(4,1) - 0) and the first element of the C matrix, (D(7,1) - 0) and
> then the corresponding median should be found out between these 3
> numbers. Similarly the median should be found out for the remaining
> elements of A,B and C matrices. My output median matrix should be the B
> matrix.
>
> E = 0 7 6
> 5 0 1
> 3 2 0
>
> I appreciate for the help.
>
> Thanks and Regards,
> Subrat Kumar Swain.


You should be able to get this done using RESHAPE and MEDIAN(X,DIM).

>> median(reshape(D',[3 3 3]),3)'

ans =

      0 7 6
      5 0 8
      3 4 0

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com