Matrix 如何将m文件作为矩阵输出多个计算?
我正在写一个m文件,其中计算了答案的数量和迭代次数。我想将每个迭代保存在一个矩阵中。我该怎么做呢Matrix 如何将m文件作为矩阵输出多个计算?,matrix,iteration,matlab,Matrix,Iteration,Matlab,我正在写一个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 j=0; 对于j
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
j=0;
对于j
定义单元格数组并在其中存储所需变量
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我想说,在Matlab中没有像++那样的“增量运算符”。是的,我不认为是这样。原始代码是一些奇怪的C++/MATLAB组合:)