Take the 2-minute tour ×

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?

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

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])=[])

share|improve this answer
this is definitely the matlab way, not my solution. –  curial Dec 2 '11 at 16:18
add comment

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.

share|improve this answer
add comment

Your Answer


