Borrar filtros
Borrar filtros

Sorting alphanumeric data and then grouping by number - is this possible?

2 visualizaciones (últimos 30 días)
I have some data like this..
0.0382705 -0.0389825 1.00923 48.8284 0.026284 2212 1 0 263 MyCulture/Cell316
0.00632027 0.0292156 1.00843 49.0162 0.0135636 2212 1 0 336 MyCulture/Cell550
0.00631382 0.0292307 1.00748 49.0026 0.0265101 2212 1 0 336 MyCulture/Nucleus0
0.00630899 0.0292418 1.00676 48.9761 0.0176806 2212 1 0 336 MyCulture/Cell550
-0.0519997 -0.020363 0.907123 47.1952 0.0358084 2212 1 0 339 MyCulture/Cell706
0.00144713 -0.00579898 1.03978 50.4856 0.0353139 2212 1 0 342 MyCulture/Cell814
0.0115323 0.023491 1.02113 50.0001 0.0126079 2212 1 0 441 MyCulture/Cell892
0.011535 0.0235026 1.02025 49.9875 0.0152807 2212 1 0 441 MyCulture/Nucleus0
0.0115374 0.0235152 1.01932 49.9722 0.0122807 2212 1 0 441 MyCulture/Cell892
0.0115877 -0.0191628 0.969385 48.0882 0.0364256 2212 1 0 528 MyCulture/Cell111
0.00670006 0.0449431 0.977987 48.8919 0.0218619 2212 1 0 537 MyCulture/Cell656
0.00649405 -0.0143382 0.991241 49.3342 0.0244002 2212 1 0 618 MyCulture/Cell555
0.00817589 -0.00516809 0.91224 47.0531 0.0266742 2212 1 0 700 MyCulture/Cell454
0.00819834 -0.00515017 0.911266 47.0264 0.00887502 2212 1 0 700 MyCulture/Nucleus0
0.00821283 -0.00513733 0.910597 47.0175 0.0138586 2212 1 0 700 MyCulture/Cell454
0.0285945 0.0294013 0.995583 48.106 0.036242 2212 1 0 704 MyCulture/Cell614
0.0286381 0.0294304 0.994406 48.0697 0.0026054 2212 1 0 704 MyCulture/Nucleus0
I've applied the natsortrows function from the following link https://au.mathworks.com/matlabcentral/fileexchange/47433-natural-order-row-sort?focused=786f2c8e-3071-0689-f6d9-7bd6ab3378b9&tab=example to sort the rows according to the last column like this...
..... MyCulture/Cell316
.
.
..... MyCulture/Cell336
.
.
..... MyCulture/Cell339
.
.
..... MyCulture/Cell700
.
.
..... MyCulture/Nucleus0
..... MyCulture/Nucleus0
..... MyCulture/Nucleus0
Is there a way to then group the data so the nucleus and cell data are grouped according to their number? So something like..
MyCulture/Cell0
MyCulture/Cell0
MyCulture/Nucleus0
MyCulture/Cell3
MyCulture/Nucleus3
MyCulture/Cell50
MyCulture/Nucleus50
MyCulture/Nucleus50
and so forth...

Respuesta aceptada

Stephen23
Stephen23 el 10 de Mzo. de 2020
>> C = {'MyCulture/Cell316';'MyCulture/Cell0';'MyCulture/Cell339';'MyCulture/Cell0';'MyCulture/Nucleus50';'MyCulture/Nucleus0';'MyCulture/Nucleus50'}
>> [~,X] = sort(str2double(regexp(C,'\d+$','once','match')));
>> D = C(X);
Giving:
>> D{:}
ans = MyCulture/Cell0
ans = MyCulture/Cell0
ans = MyCulture/Nucleus0
ans = MyCulture/Nucleus50
ans = MyCulture/Nucleus50
ans = MyCulture/Cell316
ans = MyCulture/Cell339

Más respuestas (0)

Categorías

Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by