Print matrices whose name is based on loop values

for i = 1:3
eval(['k' num2str(i) '=i']);
end
%% Doubt - How to print k1, k2, k3 based on iteration no. ???

 채택된 답변

Steven Lord
Steven Lord 2022년 7월 21일

2 개 추천

Can you dynamically create variables with numbered names like k1, k2, k3, etc.? Yes.
Should you do this? The general consensus is no. That Answers post explains why this is generally discouraged and offers several alternative approaches.

추가 답변 (0개)

카테고리

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

태그

질문:

2022년 7월 21일

답변:

2022년 7월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by