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

 채택된 답변

madhan ravi
madhan ravi 2020년 6월 5일
편집: madhan ravi 2020년 6월 5일

1 개 추천

N = size(B,2);
C = cell(N,1);
for ii = 1:N
C{ii} = [A(:,ii), B(:,ii)];
end
celldisp(C)

댓글 수: 2

Valeria Cascione
Valeria Cascione 2020년 6월 5일
Thank you very much! It works perfectly.
How can automaticaly discplay C1 and C2 individually in the workspace?
madhan ravi
madhan ravi 2020년 6월 5일
Answer is in the link I shared xD.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2020년 6월 5일

댓글:

2020년 6월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by