简体   繁体   English

Matlab为每次迭代保存变量(不使用eval)

[英]Matlab saving variable for each iteration (without using eval)

I would like to achieve this: 我想实现这一目标:

for k = 1:52
    map = reshape(map,[375 91 223]);
    x[i] = map;

    % create a new variable for each iteration x1,x2,x3,...x52  which stores 'map', 'map' is 375x91x223 size and each iteration produces a new 'map'.
end

I am trying to avoid using eval, for now I have thought about writing it to a notepad then importing it back in, but it also takes a lot of time. 我试图避免使用eval,因为现在我已经考虑过将其写到记事本中,然后再导入回去,但这也需要很多时间。 Any help appreciated. 任何帮助表示赞赏。 Thanks. 谢谢。

How about assigning rach iteration to a array index? 如何将rach迭代分配给数组索引?

x = [];

for k=1:52
  map=reshape(map,[375 91 223]);
  x{k} = map;
end

Or how about a new struct member for each iteration? 还是每次迭代都有一个新的struct成员?

x = [];
for k=1:52
  map=reshape(map,[375 91 223]);
  x.(['val' num2str(k)]) = map;
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM