MATLAB: Vector Manipulation

matrix manipulationvector

Hi Everyone,
I have a vector that is an index containing row numbers that need to be removed from a dataset. However, due the nature of my data, I know that not only do these rows need to be removed, but also the 30 rows after any of them.
My question is:
How would I add new entries to the existing vector to include each of the 30 rows following any existing entry. There should end up being 30 new entries for every existing one and I could then unique(vector) to remove any duplicate row numbers.
I hope this isn't too much of a doit4me. I don't really use anything other than dataset arrays from the statistics toolbox, so my vector manipulation skills are sort of limited.

Best Answer

row_index = [1;33;67]; %row indices
row_index = unique(cumsum(horzcat(row_index,ones(size(row_index,1),30)),2))
I threw the unique in there in case you have say (15,30) where 15 of the 15's values would overlap with some of the 30's. If there's no fear of that:
row_index = reshape(cumsum(horzcat(row_index,ones(size(row_index,1),30)),2).',[],1)
Definitely not a doit4me, as you posed your problem well, asked politely, made it interesting (matrix manipulation usually is).