2
votes

This is probably a super simple question, but here it is:

I have a <1xn> array of structs, and a vector of the indexes of the struct array that I want to remove.

So for example, if I have a removal vector of [2 6], it means I want to get rid of the 2nd and 6th struct in the array (and the array would be 2 elements shorter).

What is the clean, simple, matlab way of doing this?

2

2 Answers

4
votes

If the name of your structure is a:

a([2 6])=[]

or more generally:

ind2rm=[2 6];
a(ind2rm)= []

PS: it also works for normal arrays or matrices (e.g. A(:,[2 6])=[])

2
votes

I think this is what you need:

a = a(setdiff([1:n], [2, 6]))

a is the struct array and [2, 6] are the elements you want to remove.