Separate numbers present within a cell on multiple rows
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Alberto Acri
el 2 de Ag. de 2023
Respondida: dpb
el 2 de Ag. de 2023
Hi. I retrieved the first N numbers (largest to smallest) from the second column of the 'CountArray' array.
Now I wanted to determine the corresponding value on the first column of the 'CountArray' array by creating a column vector with these values.
I tried this way but, for example on row 22 and row 23 of cell 'matrix', there are two (equal) values because in 'values_rec' there is the same number (24).
CountArray = importdata("CountArray.mat");
N = 30;
values_rec = maxk(CountArray(:,2),N);
matrix = {};
for K = 1:height(values_rec)
[row,col] = find(CountArray(:,2) == values_rec(K));
value = CountArray(row);
matrix = [matrix;{value}];
end
matrix = cell2mat(matrix);
So I have to transform 'matrix' in this way:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1448387/image.png)
0 comentarios
Respuesta aceptada
Más respuestas (1)
dpb
el 2 de Ag. de 2023
whos -file CountArray.mat
load CountArray.mat
N = 30;
[values_rec,ix] = maxk(CountArray(:,2),N);
matrix=CountArray(ix,1);
matrix(19:30)
0 comentarios
Ver también
Categorías
Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!