【问题标题】:How to retrieve rows through a for loop in MATLAB如何通过 MATLAB 中的 for 循环检索行
【发布时间】:2016-02-02 21:39:59
【问题描述】:
[4*x1*f1   5*f2;    10*f1/x2     f2*x1*x2]

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

【问题讨论】:

标签: matlab for-loop matrix


【解决方案1】:

我认为您对 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-20
    • 1970-01-01
    • 2016-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-11
    相关资源
    最近更新 更多