How to find first 10 minimum values in a table array?
Mostrar comentarios más antiguos
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 comentario
Stephen23
el 30 de En. de 2023
Respuesta aceptada
Más respuestas (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 comentarios
Ivan Mich
el 30 de En. de 2023
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
Categorías
Más información sobre Data Preprocessing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!