Matlab - 迭代插入/附加行到矩阵 [英] Matlab - insert/append rows into matrix iteratively
本文介绍了Matlab - 迭代插入/附加行到矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在matlab中我可以交互追加矩阵行?
例如让我说空矩阵:
m = [];
当我运行for循环时,我得到了需要插入矩阵的行。 p>
例如:
for i = 1:5
row = v-x; %例如得到1 2 3
%m.append(row)?
end
所以在插入后应该看起来像这样:
m = [
在你的循环中。如果你已经知道总行号,定义
1 2 3
3 2 1
1 2 3
4 3 2 $ b在大多数编程语言中,您可以简单地将行追加到数组中/矩阵。但是我发现在matlab中很难做到。 new_row];m = zeros(row_num,column_num);
,那么在你的循环中m(i,:) = new_row;
How in matlab I can interactively append matrix with rows?
For example lets say I have empty matrix:
m = [];
and when I run the for loop, I get rows that I need to insert into matrix.
For example:
for i=1:5 row = v - x; % for example getting 1 2 3 % m.append(row)? end
so after inserting it should look something like:
m = [ 1 2 3 3 2 1 1 2 3 4 3 2 1 1 1 ]
In most programming languages you can simply append rows into array/matrix. But I find it hard to do it in matlab.
解决方案
m = [m ; new_row];
in your loop. If you know the total row number already, definem=zeros(row_num,column_num);
, then in your loopm(i,:) = new_row;
这篇关于Matlab - 迭代插入/附加行到矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文