how to combine matrices

1 回表示 (過去 30 日間)
Ham Man
Ham Man 2023 年 3 月 29 日
編集済み: Torsten 2023 年 3 月 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];

回答 (1 件)

Torsten
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]
xp = 12×30
0.0389 0.2100 0.6508 0.0781 0.4576 0.1050 0.2301 0.2978 0.2154 0.2787 0.6433 0.3096 0.4125 0.0997 0.0574 0.8028 0.8460 0.5098 0.3700 0.4292 0.8884 0.4963 0.5303 0.6257 0.5316 0.0696 0.3041 0.6604 0.7862 0.1707 0.1475 0.6412 0.6963 0.9367 0.8764 0.9421 0.4045 0.5155 NaN NaN NaN NaN 0.5805 0.0136 0.9950 0.3631 0.2132 0.3594 0.8045 0.1872 0.7862 0.5750 0.4632 0.3344 0.4083 0.0399 0.1157 0.3108 0.9686 0.5633 NaN NaN NaN 0.7756 0.0467 0.3468 0.6857 0.9192 NaN NaN NaN NaN 0.7437 0.4809 0.2057 0.9434 0.6935 0.8347 0.9452 0.3794 0.8243 0.2041 0.8604 0.9020 0.8545 0.9039 0.5499 0.7439 0.1980 0.5522 NaN NaN NaN 0.1178 0.7592 0.7770 0.7142 0.5368 NaN NaN NaN NaN 0.8453 0.7555 0.3215 0.0571 0.5620 0.0850 0.8658 0.0683 0.5648 0.2142 0.7596 0.9158 0.9735 0.1483 0.1060 0.8245 0.8324 0.5747 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 0.2459 0.4085 0.0708 0.8320 0.6566 0.5224 0.7497 0.0857 0.5760 0.3636 0.6511 0.1048 0.7797 0.0579 0.4673 0.0927 0.9970 0.5666 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 0.0022 0.4790 0.7061 0.9209 0.4400 0.9806 0.7349 0.6654 0.3385 0.5409 0.0632 0.5998 0.4576 0.6930 0.9320 0.2905 0.5810 0.6155 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 0.6228 0.6644 0.8263 0.6354 0.8700 0.9789 0.5536 0.9006 0.1163 0.6742 0.5926 0.5481 0.6999 0.7759 0.3833 0.2914 0.8815 0.1712 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 0.8553 0.6080 0.9275 0.7319 0.1563 0.6833 0.8614 0.9959 0.9722 0.3086 0.2810 0.6661 0.0350 0.1971 0.0453 0.3835 0.5597 0.8369 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 0.4036 0.9116 0.3990 0.6329 0.6962 0.9998 0.7832 0.1950 0.1253 0.9923 0.6947 0.8309 0.9028 0.1082 0.5548 0.6067 0.4842 0.3949 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 0.5940 0.2014 0.2439 0.0459 0.0228 0.3050 0.6633 0.2890 0.7329 0.6041 0.9371 0.6047 0.2448 0.8566 0.2410 0.8384 0.5134 0.5994

カテゴリ

Help Center および File ExchangeSmoothing and Denoising についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by