how to combine matrices
조회 수: 1 (최근 30일)
이전 댓글 표시
I have 4 matrix xp1,...xp4 and I want to combine them into one(xp):
I'm getting this error from the last line of script
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
any one can help please?
% xp1 is a 13874X101 matrix
% xp2 is a 13836X88 matrix
% xp3 is a 14439X87 matrix
% xp4 is a 15351X117 matrix
szx1 = max([size(xp1,1),size(xp2,1),size(xp3,1),size(xp4,1)]);
szx2 = sum([size(xp1,2),size(xp2,2),size(xp3,2),size(xp4,2)]);
xp = nan(szx1,szx2);
xp=[xp1 xp2 xp3 xp4];
댓글 수: 0
답변 (1개)
Torsten
2023년 3월 29일
편집: Torsten
2023년 3월 30일
I think you mean
xp1 = rand(2,3);
xp2 = rand(4,5);
xp3 = rand(1,4);
xp4 = rand(12,18);
szx1 = max([size(xp1,1),size(xp2,1),size(xp3,1),size(xp4,1)]);
xp1 = [xp1;nan(szx1-size(xp1,1),size(xp1,2))];
xp2 = [xp2;nan(szx1-size(xp2,1),size(xp2,2))];
xp3 = [xp3;nan(szx1-size(xp3,1),size(xp3,2))];
xp4 = [xp4;nan(szx1-size(xp4,1),size(xp4,2))];
xp = [xp1,xp2,xp3,xp4]
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!