查看单个帖子
旧 2019-12-14, 20:13   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
帖子 如何将m文件作为矩阵输出多个计算?

我正在写一个m文件,其中计算了答案的迭代次数。我想将每个迭代保存在矩阵中。我该怎么做呢?

j = 0; for j < n; %n is a user input futurevalue = P*(1+i)^j; % each of these calculation I want to save j = j+1; end

回答:

您定义一个单元格数组并将所需的变量存储在其中。

intermResults = cell(1,n); for j = 1:n; %n is a user input intermResults{j} = P*(1+i)^j; % each of these calculation I want to save end 之后,您可以访问值xx:

desiredIntermResult = intermResults{xx} 顺便说一句。我不知道MATLAB支持++运算符。

没有。我更改了代码,使其遵循Matlab语法-Jonas



更多&回答...
poster 当前离线   回复时引用此帖