简体   繁体   English

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

[英]How to find minimum value of a column imported from Excel using MATLAB

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. 我需要有关代码的帮助,该代码必须检查A列,找到最低的D值并输出相应的B和C值。 I need the output to look like. 我需要输出看起来像。

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. 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,:); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM