# How can I sort cell arrays along with vectors?

2 vues (au cours des 30 derniers jours)
dormant le 4 Jan 2024
Commenté : dormant le 5 Jan 2024
I am getting very confused by all the documentation on sorting in MATLAB, so can someone please answer this very specific question?
I have a number of numeric vectors along with two associated cell arrays, ie
How can I sort them all together with the order defined by one of the numeric vectors?
##### 3 commentairesAfficher 1 commentaire plus ancienMasquer 1 commentaire plus ancien
Stephen23 le 4 Jan 2024
Modifié(e) : Stephen23 le 5 Jan 2024
"How can I sort them all together with the order defined by one of the numeric vectors?"
With difficulty: having lots of separate variables makes this task much harder.
If you stored the data in one table then it would be very easy.
dormant le 5 Jan 2024
I tried using a table before, but had problems because some of the values in the numeric vectors were undefined or NaNs. I can't remember the details, but I'll look into it again.

Connectez-vous pour commenter.

### Réponse acceptée

Walter Roberson le 4 Jan 2024
[~, SortOrder] = sort(vtstring_datim_begs); %or as appropriate
s_ends = vtstring_datim_ends(SortOrder);
s_durs = vtstring_durs(SortOrder);
s_ids = vtstring_ids(SortOrder);
s_max_MLs = vtstring_max_MLs(SortOrder);
%and so on
##### 1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
dormant le 5 Jan 2024
Many thanks.

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Shifting and Sorting Matrices dans Help Center et File Exchange

R2023b

### Community Treasure Hunt

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

Start Hunting!

Translated by