如何使用MATLAB查找从Excel导入的列的最小值

时间:2022-09-08 22:49:52

I have a set of values in the following pattern.

我有以下模式中的一组值。

A   B   C   D
1   5   6   11
2   6   5   21
3   7   3   42
4   3   7   22
1   2   3   54
2   3   2   43
3   4   3   27
4   3   2   14

I exported the every column into MATLAB workspace as follows.

我将每列导出到MATLAB工作区,如下所示。

A = xlsread('F:\R.xlsx','Complete Data','A2:A43'); 
B = xlsread('F:\R.xlsx','Complete Data','B2:B43'); 
C = xlsread('F:\R.xlsx','Complete Data','C2:C43'); 
D = xlsread('F:\R.xlsx','Complete Data','D2:D43'); 

I need help with code where the it has to check the Column A, find the lowest D value and output the corresponding B and C values. I need the output to look like.

我需要帮助代码,它必须检查列A,找到最低的D值并输出相应的B和C值。我需要输出看起来像。

1   5   6   11
2   6   5   21
3   4   3   27
4   3   2   14

I read through related questions and understand that I need to make it a matrix and sort it based on the element on the 4th column using

我阅读了相关的问题,并了解我需要将其作为矩阵,并根据第4列中的元素对其进行排序

sortrows

and get indices of the sorted elements. But I am stuck here. Please Guide me.

并获取已排序元素的索引。但我被困在这里。请指导我。

1 个解决方案

#1


3  

  1. You can export those columns in one go as:

    您可以一次性导出这些列:

    ABCD = xlsread('F:\R.xlsx','Complete Data','A2:D43');
    
  2. Now use sortrows to sort the rows according to the first and the fourth column.

    现在使用sortrows根据第一列和第四列对行进行排序。

    req = sortrows(ABCD, [1 4]);
    
  3. ☆ If all elements of the first column exist twice then:

    ☆如果第一列的所有元素都存在两次,那么:

    req = req(1:2:end,:);  
    

    ☆ If it is not necessary that all elements of the first column will exist twice then:

    ☆如果没有必要将第一列的所有元素都存在两次,那么:

    [~, ind] = unique(req(:,1));
    req =  req(ind,:);
    

#1


3  

  1. You can export those columns in one go as:

    您可以一次性导出这些列:

    ABCD = xlsread('F:\R.xlsx','Complete Data','A2:D43');
    
  2. Now use sortrows to sort the rows according to the first and the fourth column.

    现在使用sortrows根据第一列和第四列对行进行排序。

    req = sortrows(ABCD, [1 4]);
    
  3. ☆ If all elements of the first column exist twice then:

    ☆如果第一列的所有元素都存在两次,那么:

    req = req(1:2:end,:);  
    

    ☆ If it is not necessary that all elements of the first column will exist twice then:

    ☆如果没有必要将第一列的所有元素都存在两次,那么:

    [~, ind] = unique(req(:,1));
    req =  req(ind,:);