Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
![]() |
#1 |
高级会员
注册日期: 2019-11-21
帖子: 3,006
声望力: 66 ![]() |
![]()
我正在写一个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 更多&回答... |
![]() |
![]() |