필터 지우기
필터 지우기

Matrix dimension reduction based on summation

조회 수: 8 (최근 30일)
Fayyaz
Fayyaz 2015년 4월 14일
답변: David Young 2015년 4월 14일
Hi,
I have 81*81 matrix. I need to reduce this matrix dimension to, let say, 10*10. Let suppose in the new 10*10 matrix, 1st column is equal to the sum of 1 to 10 columns, similarly 2nd column (in the new matrix) is the sum of 11 to 20 columns and so on. Similarly for the rows too.
How we can code this in MATLAB.
Thanks
  댓글 수: 2
pfb
pfb 2015년 4월 14일
a column in a 10x10 matrix has 10 entries. A column in a 81x81 matrix has 81 entries. How can a the sum of 10 81x1 vectors be a 10x1 vector?
Fayyaz
Fayyaz 2015년 4월 14일
편집: Fayyaz 2015년 4월 14일
thanks for your comment.
I am not deleting any entries. I am reducing the matrix dimension from 81*81 to 10*10 based on summing those rows and columns.
i.e 1 (in 10*10)=1+2+...+10 (in 81*81)
2 (in 10*10)=11+....20 (in 81*81)
. . .
10 (in 10*10)= 71+72+.... 81 (in 81*81)

댓글을 달려면 로그인하십시오.

채택된 답변

David Young
David Young 2015년 4월 14일
If you try to reduce an 81 x 81 matrix to a 10 x 10 matrix it is bound to be messy, because 81 is not a multiple of 10. You have one row and one column left over.
Instead, let's suppose you want to reduce an 80 x 80 matrix to 10 x 10 by summing the values in each 8 x 8 block. There are various ways of doing this - here's one that uses accumarray:
% Test data
a = rand(80, 80);
% The factors by which to reduce the size
rowReduce = 8; % first dimension
colReduce = 8; % second dimension
% Get the subscripts for each element of the input matrix
[subsAi, subsAj] = ndgrid(1:size(a,1), 1:size(a,2));
% Compute the corresponding output subscripts
subsBi = 1 + floor((subsAi-1)/rowReduce);
subsBj = 1 + floor((subsAj-1)/colReduce);
% Carry out the summation
b = accumarray([subsBi(:) subsBj(:)], a(:)); % b is reduced matrix
% See if the overall summation was correct
disp(abs(sum(a(:)) - sum(b(:)))); % should be small
The code above will work with your original problem, which is to reduce an 81 x 81 matrix. You can still set the reduction factor to get a 10 x 10 result, but the blocks that are summed to produce each output value will vary in size.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by