calling a matrix with different names in a for loop

I have three matrixes with different names as NPV_1, NPV2 and NPV_3. I have tried the below but It did not work. Can you please help
for i = 1:3
fm =forfor sprintf('NPV_%d',i);
NPV_Mat = fm;
end

댓글 수: 2

"I have three matrixes with different names as NPV_1, NPV2 and NPV_3"
Accessing separate variable names like that is one way that beginners force themselves into writing slow, complex, obfuscated, buggy code that is hard to debug. Read this to know why:
I agree and going to fix it. Thanks a lot for sharing this

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

 채택된 답변

Stephen23
Stephen23 2019년 9월 5일
편집: Stephen23 2019년 9월 5일
Simply put your three matrices into one cell array, then your task is trivial:
C = {NPV_1, NPV2, NPV_3};
for k = 1:numel(C)
M = C{k};
... do whatever with M
end

추가 답변 (0개)

카테고리

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

태그

질문:

2019년 9월 5일

댓글:

2019년 9월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by