How to find median value of a columns of a matrix ?
6 次查看(过去 30 天)
显示 更早的评论
I have a zero-padded 8*8 matrix, and I want to find the median value of 3*3 block and then change the value of the middle element to this median value, then go to next block and do the same. how can I do this?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/729779/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/729784/image.png)
Here is my code:
A=[44 25 22 55 21 11;35 43 2 23 45 66;12 22 19 12 76 88; 21 23 43 12 65 75;...
10 86 56 55 23 97;23 75 88 5 55 71];
A_padded = padarray(A, [1 1]); % my 'zero-padding'
Thanks in advance for the help!
0 个评论
采纳的回答
Walter Roberson
2021-9-5
编辑:Walter Roberson
2021-9-5
A=[44 25 22 55 21 11;35 43 2 23 45 66;12 22 19 12 76 88; 21 23 43 12 65 75;...
10 86 56 55 23 97;23 75 88 5 55 71];
A_padded = padarray(A, [1 1]); % my 'zero-padding'
A_padded
simpliest_way = medfilt2(A_padded)
more_complicated = blockproc(A_padded, [1 1], @(B) median(B.data(:)), 'BorderSize', [1 1], 'TrimBorder', false)
5 个评论
Walter Roberson
2021-9-5
编辑:Walter Roberson
2021-9-5
What size of output are you expecting?
For example,
A B C D
E F G H
I J K L
First block would be [A B C] and you said you want to replace the middle with the median, which would give you [A M1 C] where M1 is a median. Then you slide over to [B C D] and you want to replace the middle with the median, which would give you [B M2 D] . Now you want to put those two together on output... and you would want the first output row to look like
[A M1 C B M2 D]
??? So if there were N columns of input, then you would want the output to have (N-2)*3 columns ??
Or do you want to output only the medians, so the output for the first row would be [M1 M2] ?
If you want to output only the medians, and it is for the 1 x 3 sliding, then the code is what I posted earlier,
more_complicated = blockproc(A_padded, [1 1], @(B) median(B.data(:)), 'BorderSize', [0 1], 'TrimBorder', false)
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!