简体   繁体   English

for循环的输出作为矩阵MATLAB

[英]output of for loop as a matrix MATLAB

the following function gives as output a 3x3 matrix 以下函数提供了一个3x3矩阵作为输出

S=myfunction(i,3)

I would like to know please if there is a way to stock the output of the following loop in a way that I can recall the matrix from each step. 我想知道是否有一种方法可以存储下一个循环的输出,以便我可以从每个步骤中调出矩阵。

 for i=1:8
 S=myfunction(i,3)
 end

This loop at each step gives a different matrix and I would like to give a name to each matrix from each step for exampe S1, S2 , S3 .. 每个步骤的此循环给出了一个不同的矩阵,我想为例如S1,S2,S3等每个步骤的每个矩阵命名。

Is this possible? 这可能吗? or should I save the result in a 3 x (24) huge matrix? 还是应该将结果保存在3 x(24)的巨大矩阵中?

Thank you 谢谢

example of output: 输出示例:

 for i=1:8
 S=myinfluence(i,3)
 end

 S = 

'HH'    'HH'    'HH'
'HH'    'HH'    'HH'
'HH'    'HH'    'HH'

The easy way seems to me is to have a three dimensional matrix, and just index along the third dimension to save the intermediate result. 在我看来,最简单的方法是拥有一个三维矩阵,并且只需沿三维索引即可保存中间结果。

for i = 1:8
  S(:, :, i) = myinfluence(i,3);
end

then you can access each iteration by calling S(:, : , 1) or S(:, : , 2) or S(:, : , 3) and so on. 那么您可以通过调用S(:, : , 1)S(:, : , 2)S(:, : , 3)等来访问每个迭代。

using the : as an index means that all of the entries along the appropriate index of the right hand side of assignment will be automatically copied to the corresponding index in the left hand side of assignment. 使用:作为索引意味着将沿着分配右侧的适当索引的所有条目自动复制到分配左侧的相应索引。

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

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