calling a matrix with different names in a for loop

26 views (last 30 days)
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;
Yaser Khojah
Yaser Khojah on 5 Sep 2019
I agree and going to fix it. Thanks a lot for sharing this

Sign in to comment.

Accepted Answer

Stephen23 on 5 Sep 2019
Edited: Stephen23 on 5 Sep 2019
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

More Answers (0)


Community Treasure Hunt

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

Start Hunting!