How to save all values generated from a for statement in different variables

1 次查看(过去 30 天)
Hello,
I'm using a for statement to extract values from a matrix depending on i.
for i=1:intn % number of sources Ls= filename(i+1,5)
In this case, I need to save all generated values of Ls as Ls1, Ls2, Ls3, etc.. I tried Ls(i) but it didn't work. Does anyone know how to integrate i into the string name?
Any help would be highly appreciated!
Thanks,
  3 个评论
Adam
Adam 2015-3-6
Unless intn is 2 it sounds like you used it incorrectly in that case, but you haven't posted your code so it is impossible to say much more.

请先登录,再进行评论。

回答(1 个)

Ingrid
Ingrid 2015-3-6
you could try to use a structure that would look something like this:
for i =1:intn
currentName = ['Ls' num2str(i)]
results.(currentName) = filename(i+1,5);
end
than you can store the Ls1,Ls2,... as follows
save filename results -struct

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by