Assign name to matrices in a loop

Hi,
I'm trying to create new matrices using loop, by concateneting other matrices.
For example I have
A=[1 4 B=[7 10
2 5 8 11
3 6] 9 12]
And I want to create
C1=[1 7 C2)=[4 10
2 8 5 11
3 9] 6 12]
If I use
N=2
for i=1:2
C=[A(:,i) B(:,i)]
end
How do assign a dynamic name to each loop (C1 and C2)? How to I disply each loop as new variable (new matrix)?
Thank you very much

 Accepted Answer

madhan ravi
madhan ravi on 5 Jun 2020
Edited: madhan ravi on 5 Jun 2020
N = size(B,2);
C = cell(N,1);
for ii = 1:N
C{ii} = [A(:,ii), B(:,ii)];
end
celldisp(C)

2 Comments

Thank you very much! It works perfectly.
How can automaticaly discplay C1 and C2 individually in the workspace?
Answer is in the link I shared xD.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!