## find mean for each 4 row in 124x7 matrix

### nada seddeeq (view profile)

さんによって質問されました 2019 年 1 月 20 日

### nada seddeeq (view profile)

さんによって コメントされました 2019 年 1 月 21 日

### madhan ravi (view profile)

さんの 回答が採用されました
Hi all ,,,
I have matrix U=124 x 7
I want to find the mean through all 4 rows of each column
the result be 31 x7

#### 0 件のコメント

サインイン to comment.

## 2 件の回答

2019 年 1 月 20 日

### madhan ravi (view profile)

2019 年 1 月 20 日
採用された回答

b=mat2cell(U,repmat(4,1,size(U,1)/4)); % where U is 124 X 7 matrix
R=cellfun(@(x) mean(x),b,'un',0);
Result=vertcat(R{:})

### nada seddeeq (view profile)

2019 年 1 月 20 日
Thank you alot ..it is work
if there is a simple loop to do that..

### madhan ravi (view profile)

2019 年 1 月 21 日
"if there is a simple loop to do that.."
[m,n]=size(U);
Result=zeros(m/4,n);
for k = 1:m/4
Result(k,:)=mean(U(k*4-3:k*4,:));
end

### nada seddeeq (view profile)

2019 年 1 月 21 日
That's wonderful ......thank you again

サインイン to comment.

### Image Analyst (view profile)

2019 年 1 月 20 日

You can do it in as little as two lines of code with blockproc() from the Image Processign Toolbox:
U = randi(9, 124, 7); % Original sample data
% Define the function that we will apply to each block.
% This function will return a value that is the mean of the elements in the block.
% Output array will be 31 by 7.
meanFilterFunction = @(theBlockStructure) mean(theBlockStructure.data(:));
% Block process the image to replace every pixel in the
% 4 pixel by 1 pixel block by the mean of the pixels in the block.
blockSize = [4 1];
blockMeanArray = blockproc(U, blockSize, meanFilterFunction); % Works.
blockproc() moves along in "jumps" of the block size that you specify - it does not slide over by one element at a time like conv2() does. If you'd used conv2() you would have to subsample the result.

### nada seddeeq (view profile)

2019 年 1 月 20 日
Thank you
but the result was not the elements mean
Image Analyst

### Image Analyst (view profile)

2019 年 1 月 21 日
It most certainly was. I just double checked it. Check your numbers again.

サインイン to comment.

Translated by