poster
2019-12-14, 20:13
我正在写一个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
更多&回答... (https://stackoverflow.com/questions/4812833)
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
更多&回答... (https://stackoverflow.com/questions/4812833)