adding multiple arrays into one big array

조회 수: 2 (최근 30일)
Kafayat Olayinka
Kafayat Olayinka 2019년 8월 8일
댓글: Kafayat Olayinka 2019년 8월 8일
Hi,
I have multiple array with different sizes such as A1=(200 by 3000),A2=(280 by 3020).
I will like to create a zeros matrix: A=zeros(480 by 3020) where i'm able to stack each rows of A1 and A2 inside the new array A.
Such that A=[A1;A2]
what should i do?

채택된 답변

Andrei Bobrov
Andrei Bobrov 2019년 8월 8일
편집: Andrei Bobrov 2019년 8월 8일
s1 = size(A1);
s2 = size(A2);
s22 = max(s1(2),s2(2));
A = [A1,zeros(s1(1),s22 - s1(2));A2,zeros(s2(1),s22 - s2(2))];
  댓글 수: 3
Andrei Bobrov
Andrei Bobrov 2019년 8월 8일
Let C = {A1,A2,A3,..,An}';
[m,n] = cellfun(@size,C,'un',0);
nn = max([n{:}]);
A = cell2mat(cellfun(@(x,y,z)[x,zeros(y,nn-z)],C,m,n,'un',0));
Kafayat Olayinka
Kafayat Olayinka 2019년 8월 8일
It worked! thank you very much!!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Types에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by