Combining many matrices into one using loop.

I' m running a for loop say 'n' times,everytime different column size of matrices will be generated i.e. 100x8, 100×7, 100×6, 100×5 till 100×1.It means, every R×C matrix in the loop, R is fixed (say, 100) but C varies 8 to 1. I have to join all these matrices into one,such that at last run I will have a matrix of size 100x36 for the above example. How to solve this?

 采纳的回答

Store them in a cell and then concatenate, e.g.,
for i=1:4
C{1,i}=rand(10,randi(5));
end
C,
C = 1×4 cell array
{10×1 double} {10×4 double} {10×4 double} {10×3 double}
A=[C{:}]
A = 10×12
0.1012 0.5847 0.0422 0.0927 0.3365 0.5994 0.7556 0.2340 0.8685 0.6933 0.5492 0.4385 0.3521 0.9806 0.4934 0.5638 0.9683 0.5351 0.7645 0.3812 0.7980 0.2392 0.4712 0.9655 0.7107 0.3087 0.6544 0.8404 0.5521 0.2502 0.5676 0.0760 0.5621 0.7269 0.8393 0.7572 0.7807 0.4537 0.8952 0.5111 0.9963 0.3561 0.5162 0.0777 0.9753 0.1392 0.3588 0.0231 0.2646 0.9981 0.3786 0.8553 0.0252 0.9553 0.5662 0.6819 0.9702 0.8811 0.3065 0.9597 0.5111 0.5923 0.8939 0.0624 0.6811 0.1550 0.0092 0.2848 0.6800 0.4390 0.1945 0.7882 0.3430 0.0192 0.6772 0.3248 0.9243 0.7624 0.0232 0.7866 0.0629 0.4554 0.8123 0.7840 0.7077 0.9853 0.2211 0.0838 0.7731 0.0755 0.3571 0.1842 0.6388 0.0938 0.9734 0.6791 0.6776 0.8526 0.8012 0.6263 0.6020 0.3623 0.8503 0.4096 0.5787 0.1684 0.9371 0.1240 0.3658 0.9243 0.7607 0.5523 0.9924 0.9549 0.5292 0.6462 0.1245 0.5942 0.0552 0.0137

更多回答(0 个)

类别

帮助中心File 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