4

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?

1 Answer 1

7

L1 = Lst([Lst.Type]==1); will give you the subset L1 of Lst where Type == 1.

Likewise, you can use idx1 = find([Lst.Type]==1) to memorize your indexes.

EDIT: the above uses the [] operator to aggregate the field elements Type of Lst into an array. To your comment/question, you could use the exact same operator also to obtain an array of specific field elements X of a subset of the structured array, as in

X1 = [Lst([Lst.Type]==1).X];
Sign up to request clarification or add additional context in comments.

1 Comment

thanks! not sure if to open another question for this or not, but do you know how to get a lst of only X for example, I want a field in teh lst and not the struct of the items in the list- but a list of only inner items.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.