How to find first 10 minimum values in a table array?
이전 댓글 표시
I have a table array with 5 columns (1,2,3,5 are numbers and column 4 have letters). (I am uploading one example of this array) I would like to exctract from this array the first 10 minimum values, depending the number in column 3.
I tried these
but are no use for my purpose.
T=readtable('input.txt');
A=T(:,1);
B=T(:,1);
C=T(:,1);
D=T(:,1);
E=T(:,1);
Minm=min(T,[],1)
Could you please help me?
댓글 수: 1
Stephen23
2023년 1월 30일
채택된 답변
추가 답변 (2개)
You can sort the array you want and arrange the other arrays/ table into that order. You can pick the first whatever number you want after arraning in the descending order.
T = readtable('https://in.mathworks.com/matlabcentral/answers/uploaded_files/1278020/input.txt') ;
c1 = T.(1) ;
c2 = T.(2) ;
c3 = T.(3) ;
c5 = T.(5) ;
[val,idx] = sort(c3) ;
iwant = T(idx,:)
댓글 수: 2
Ivan Mich
2023년 1월 30일
Okay, but can you give us example, what is that you expect from this particular example. You know, by definition it cannot exist 10 minimum values. I thought you need 10 values from one particular column, but when you say from the table, I'm not sure what that means.
T = readcell('https://in.mathworks.com/matlabcentral/answers/uploaded_files/1278020/input.txt');
column = 3; % column by which you want to sort
T_sort = sortrows(T, column); % sort by column
T_sort(1:10,:) % show first 10 values
You can just enter column = 3 in my previous code and display 10 values from the matrix
Another solution is to use readcell function instead of read table.
T = readcell('https://in.mathworks.com/matlabcentral/answers/uploaded_files/1278020/input.txt'); % read from file
column = 1; % column by which you want to sort
T_sort = sortrows(T, column); % sort by column
T_sort(1:10, column) % show first 10 values
카테고리
도움말 센터 및 File Exchange에서 Data Preprocessing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!