![]() |
如何将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 [B]回答:[/B] 您定义一个单元格数组并将所需的变量存储在其中。 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支持++运算符。 [I]没有。我更改了代码,使其遵循Matlab语法-Jonas[/I] [url=https://stackoverflow.com/questions/4812833]更多&回答...[/url] |
所有时间均为北京时间。现在的时间是 23:15。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.