필터 지우기
필터 지우기

Concatenation with array of different dimensions

조회 수: 3 (최근 30일)
Del
Del 2012년 9월 23일
How do you concatenate arrays with different dimensions?
So for example, if I have a1=[1;2]; a2=[4;1;9]; a3=[5];
and what I wanna produce is the matrix:
A=[1 4 5; 2 1 0; 0 9 0]

답변 (2개)

Wayne King
Wayne King 2012년 9월 23일
편집: Wayne King 2012년 9월 23일
a1=[1;2]; a2=[4;1;9]; a3=[5];
a1 = padarray(a1,1,'post');
a3 = padarray(a3,2,'post');
A = reshape(cat(1,a1,a2,a3),3,3);

Andrei Bobrov
Andrei Bobrov 2012년 9월 23일
편집: Andrei Bobrov 2012년 9월 23일
a = {[1;2],[4;1;9],5}
m = numel(a);
k = cellfun(@numel,a);
out = zeros(max(k),m);
for jj = 1:m
out(1:k(jj),jj) = a{jj}(:);
end
or
a = {[1;2],[4;1;9],5};
m = numel(a);
k = cellfun(@numel,a);
i1 = zeros(max(k),m);
i1(k + (0:m-1)*max(k)) = 1;
out = flipud(cumsum(i1(end:-1:1,:)));
out(out>0) = cat(1,a{:});

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by