2016-02-02 35 views
-2
[4*x1*f1 5*f2; 10*f1/x2  f2*x1*x2] 

我有一个2x2矩阵,但我需要单独检索每一行。我将如何遍历它,以便MATLAB可以找到矩阵的长度,并保持循环打开,直到索引等于所述矩阵中的行数?看起来,MATLAB函数被设计为预先打包以遍历行,但我需要为自己编写一个自定义函数。如何在MATLAB中通过for循环检索行

+1

'为R = 1:尺寸(A,1)'? – David

+2

请参见:[Matrix索引](http://www.mathworks.com/help/matlab/math/matrix-indexing.html) – excaza

回答

0

我觉得你有兴趣在语法A(1,:)获得第1行,等

A = [4*x1*f1 5*f2; 10*f1/x2  f2*x1*x2]; 
[r,~] = size(A); % get the number of rows, save as 'r' 
for i = 1:r %% loop over the number of rows 
    row = A(i,:); %% save the individual row 
    %% my_func(row) <<-- put whatever code you want here 
end