I have a struct array named Lst. Every struct has the following form:
Point (x,y)
Type (1-6)
I want get the separate array of points for each type. How can I get it?
Lst(Lst.Type==1);
won’t work since Type is not a field of Lst but of Lst(i).
In addition, is there a way to save the indexes of each item or an alternative way to then combine them again to the original order?
L1 = Lst([Lst.Type]==1);will give you the subsetL1ofLstwhereType == 1.Likewise, you can use
idx1 = find([Lst.Type]==1)to memorize your indexes.EDIT: the above uses the
[]operator to aggregate the field elementsTypeofLstinto an array. To your comment/question, you could use the exact same operator also to obtain an array of specific field elementsXof a subset of the structured array, as in