|
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
|