Effacer les filtres
Effacer les filtres

Arrange points by y cordinate within a stucture array

2 vues (au cours des 30 derniers jours)
Ikenna Okoye
Ikenna Okoye le 8 Mai 2020
Commenté : Ameer Hamza le 11 Mai 2020
Would anyone know a way of arranging a structure arrays points by y cordinate indescending order? I dont even know how to go about starting this. Any help would be appreciated.
For example i have a structure with each field being an element, each element has a cordinate [x,y,z] and id like to order this coulmn of points by the y cordinate.
ive tried using a nested for loop to acheive this to start parcing through the structure, but am not capturing all of the fields in the structure. OutputTable is the structure.
for iRun = 1:1:length(outputTable)
for iObj = 1:1:length(outputTable(iRun).tubingRuns.objects)
objectTable = sort([outputTable.tubingRuns(iRun).objects(iObj).centroid(2)]);
sortTable(iRun).tubingRuns.objects(nextIndex).centroid = objectTable;
end
end

Réponse acceptée

Ameer Hamza
Ameer Hamza le 8 Mai 2020
Modifié(e) : Ameer Hamza le 8 Mai 2020
Try something like this
% example struct array 's'.
s(1).coordinate = [1 4 3]; s(1).id = 1;
s(2).coordinate = [8 0 7]; s(2).id = 2;
s(3).coordinate = [5 6 12]; s(3).id = 3;
x = vertcat(s.coordinate);
[~, idx] = sort(x(:,2));
s = s(idx);
elements of 's' are sorted according to second column of 'coordinate'.
  6 commentaires
Ikenna Okoye
Ikenna Okoye le 11 Mai 2020
Thanks so much for explaining!
Ameer Hamza
Ameer Hamza le 11 Mai 2020
I am glad to be of help.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

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

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by