【问题标题】:Index row and index column of the minimum value matrix A in 2nd until 3rd row and 2nd column最小值矩阵 A 在第 2 到第 3 行和第 2 列的索引行和索引列
【发布时间】:2021-09-15 02:32:18
【问题描述】:

我的 MATLAB 代码如下:

clear all;
clc;
A=[1 0 3;4 3 0;5 10 3]
[rows,columns]=find(A(:,2)==min(A(2:3,2)))

我想在第 2 到第 3 行和第 2 列中找到最小值矩阵 A 的索引行和索引列。手动,我们可以找到最小值为 3,索引 row=2 和 index column=2(见下图)

但是如果我使用上面的代码,我的问题是不一样的。谁能帮帮我?

【问题讨论】:

    标签: matlab minimum indices


    【解决方案1】:

    由于您正在输入列索引,因此无需再次查找。更好的方法是这样做:

    col_ind = 2;
    [minimum, row_ind]  = min(A(2:3,col_ind)); 
    row_ind = row_ind+1;      %1 is added since first row is skipped in above line
    

    在您的代码中,

    • A(2:3, 2) 只有 1 列。所以columns 永远是1
    • 如果A(1,2) 也与最小值相同,您的代码将返回第一个值的行索引。
    • 在计算中跳过第一行和第一列这一事实并未包含在输出中。

    解决上述问题:

    [rows,columns]=find(A(2:3,2)==min(A(2:3,2)));
    rows=rows+1;     columns=columns+1;
    

    【讨论】:

      猜你喜欢
      • 2015-12-29
      • 2018-11-02
      • 1970-01-01
      • 2019-09-12
      • 2021-09-14
      • 2021-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多