how to combine matrix easier

2 views (last 30 days)
metumetu on 11 Mar 2020
Commented: BobH on 12 Mar 2020
I want. How can i do this (below code block) with a loop?
I have to do this with a loop because, i will be doing this with a lots of a matrices. please help me.
Thank you.
a1=[1,2,3; 4,5,6; 7,8,9]
a2=[10,11,12; 13,14,15; 16,17,18]
a3=[19,20,21; 22,23,24; 25,26,27]
Ameer Hamza
Ameer Hamza on 11 Mar 2020
BobH, the actual problem is that OP wants to do it with lots of matrices, so manually concatenating array will not be practical.

Sign in to comment.

Accepted Answer

Ameer Hamza
Ameer Hamza on 11 Mar 2020
If the data is stored properly, i.e., in cell array instead of using separate variables, the following one-liner will work
a{1}=[1,2,3; 4,5,6; 7,8,9];
a{2}=[10,11,12; 13,14,15; 16,17,18];
a{3}=[19,20,21; 22,23,24; 25,26,27];
C = cell2mat(cellfun(@(x) x(:)', a, 'UniformOutput', 0)')';

Sign in to comment.

More Answers (0)


Community Treasure Hunt

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

Start Hunting!

Translated by