How i can combine three or more than three matrix?

조회 수: 1 (최근 30일)
Akash Pal
Akash Pal 2021년 8월 10일
편집: Stephen23 2021년 8월 10일
y=[repmat(x1,size(x2,1),1),repelem(x2,size(x1,1),1)];
I am writing this code for combining two matrix where the row number is different but column is same .
My question is how i can combine more than two matrix where their row number is differnt but column is same ?

채택된 답변

Stephen23
Stephen23 2021년 8월 10일
편집: Stephen23 2021년 8월 10일
Note that you will run out of memory very quickly as you increase the number of matrices.
format compact
inp = {rand(3,4),rand(4,4),rand(5,4)}; % all matrices in one cell array.
celldisp(inp)
inp{1} = 0.3652 0.5458 0.7328 0.9886 0.1774 0.4146 0.6908 0.7239 0.5397 0.1625 0.8757 0.0996 inp{2} = 0.4526 0.4298 0.2415 0.8247 0.5996 0.3380 0.2754 0.7322 0.2394 0.6964 0.4858 0.6903 0.1400 0.8696 0.7921 0.3204 inp{3} = 0.3385 0.7161 0.8820 0.6369 0.9931 0.9668 0.0144 0.1382 0.8860 0.5127 0.3950 0.9405 0.0639 0.5230 0.1287 0.5097 0.7254 0.0057 0.9713 0.4787
fun = @(m)1:size(m,1);
idr = cellfun(fun,inp,'uni',0);
[idr{:}] = ndgrid(idr{:}); % comma-separated lists
baz = @(m,r)m(r(:),:);
tmp = cellfun(baz,inp,idr,'uni',0);
out = horzcat(tmp{:})
out = 60×12
0.3652 0.5458 0.7328 0.9886 0.4526 0.4298 0.2415 0.8247 0.3385 0.7161 0.8820 0.6369 0.1774 0.4146 0.6908 0.7239 0.4526 0.4298 0.2415 0.8247 0.3385 0.7161 0.8820 0.6369 0.5397 0.1625 0.8757 0.0996 0.4526 0.4298 0.2415 0.8247 0.3385 0.7161 0.8820 0.6369 0.3652 0.5458 0.7328 0.9886 0.5996 0.3380 0.2754 0.7322 0.3385 0.7161 0.8820 0.6369 0.1774 0.4146 0.6908 0.7239 0.5996 0.3380 0.2754 0.7322 0.3385 0.7161 0.8820 0.6369 0.5397 0.1625 0.8757 0.0996 0.5996 0.3380 0.2754 0.7322 0.3385 0.7161 0.8820 0.6369 0.3652 0.5458 0.7328 0.9886 0.2394 0.6964 0.4858 0.6903 0.3385 0.7161 0.8820 0.6369 0.1774 0.4146 0.6908 0.7239 0.2394 0.6964 0.4858 0.6903 0.3385 0.7161 0.8820 0.6369 0.5397 0.1625 0.8757 0.0996 0.2394 0.6964 0.4858 0.6903 0.3385 0.7161 0.8820 0.6369 0.3652 0.5458 0.7328 0.9886 0.1400 0.8696 0.7921 0.3204 0.3385 0.7161 0.8820 0.6369

추가 답변 (1개)

KSSV
KSSV 2021년 8월 10일
편집: KSSV 2021년 8월 10일
y=cat(1,repmat(x1,size(x2,1),1),repelem(x2,size(x1,1),1));
Or
y=[repmat(x1,size(x2,1),1) ; repelem(x2,size(x1,1),1)];
  댓글 수: 2
Akash Pal
Akash Pal 2021년 8월 10일
Thank you for giving the answer.But i did it already by myself .i asked if my matrix number is more than 2 or three.then what will be the procedure .
example a=3X4 ,b=4X4,c=5X4 then my output matrix should be y=60X12 ;
i want to form this type of matrix.
KSSV
KSSV 2021년 8월 10일
Store the matrices into a cell and use cat.

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by