how to sort a cell array inside a struct?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Chiara Scarpellini
el 29 de Jul. de 2021
Respondida: Peter Perkins
el 29 de Jul. de 2021
I have this struct and I have to sort every vector on the right side
T=table(string,ID_number);
[G, IDs] = findgroups(T.string);
C = splitapply(@(x){x},T.ID_number,G);
Name_Code = struct('name', cellstr(IDs), 'Code', C);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/698037/image.png)
0 comentarios
Respuesta aceptada
Peter Perkins
el 29 de Jul. de 2021
I think you would be better off with a table than a struct.
Name_Code = table(IDs, C,'VariableNames',["Name" "Codes"])
Name_Code.Codes = cellfun(@sort,Name_Code.Code,"UniformOutput",false)
But Jan is correct, do it at the source.
0 comentarios
Más respuestas (1)
Jan
el 29 de Jul. de 2021
Expand
C = splitapply(@(x) {x}, T.ID_number, G);
to
C = splitapply(@(x) {sort(x)}, T.ID_number, G);
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!