简体   繁体   中英

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.

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.

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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