Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matrix 如何将m文件作为矩阵输出多个计算?_Matrix_Iteration_Matlab - Fatal编程技术网

Matrix 如何将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

我正在写一个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
定义单元格数组并在其中存储所需变量

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组合:)