reshape a matrix in a special manner

1 回表示 (過去 30 日間)
Rica
Rica 2012 年 11 月 26 日
Hi!
how could i make this matrix reschaping:
% A=[A(:,1) A(:,2) A(:,3).....A(:,130)]
TO
C1= mean([A(:,1)....A(:,10)],2)
C2=mean([A(:,11)........A(:,20)],2)
C3=mean([A(:,21)........A(:,30)],2)
C=[C1 C2 C3..........C13]
Thank you

採用された回答

Pedro Villena
Pedro Villena 2012 年 11 月 26 日
編集済み: Pedro Villena 2012 年 11 月 26 日
A = rand(100,130);
step = 10;
C = cell2mat(arrayfun(@(i,j) mean(A(:,i:j),2),...
1:step:length(A)-step, 1+step:step:length(A),'un',0))

その他の回答 (3 件)

José-Luis
José-Luis 2012 年 11 月 26 日
編集済み: José-Luis 2012 年 11 月 26 日
Faster:
a = rand(100,130);
[m n] = size(a);
a = reshape(a,m,10,n/10); %Provided n is divisible by 10
your_mat = squeeze(mean(a,2));
One liner of the above:
your_mat = squeeze(mean(reshape(a,size(a,1),10,size(a,2)/10),2));

Matt J
Matt J 2012 年 11 月 26 日
Using the function below
downsampn(A,[size(A,1),10]);
function M=downsampn(M,bindims)
%DOWNSAMPN - simple tool for downsampling n-dimensional nonsparse arrays
%
% M=downsampn(M,bindims)
%
%in:
%
% M: an array
% bindims: a vector of integer binning dimensions
%
%out:
%
% M: the downsized array
nn=length(bindims);
[sz{1:nn}]=size(M); %M is the original array
sz=[sz{:}];
newdims=sz./bindims;
args=num2cell([bindims;newdims]);
M=reshape(M,args{:});
for ii=1:nn
M=mean(M,2*ii-1);
end
M=reshape(M,newdims);

Matt J
Matt J 2012 年 11 月 26 日
m=mean(reshape(A,[],10,13),2);
reshape(m,[],13);

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by