Vector Manipulation
古いコメントを表示
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.
採用された回答
その他の回答 (1 件)
Fangjun Jiang
2011 年 7 月 22 日
The best way is to provide some example data so we can understand your question better. Below is my guess.
Data=(1:1000)';
Index=1:100:1000
for k=1:length(Index)
EndIndex=min(Index(k)+30,length(Data));
% remove
%Data(Index(k):EndIndex)=[];
% or provide new data
Data(Index(k):EndIndex)=0;
end
2 件のコメント
Sean de Wolski
2011 年 7 月 22 日
Removing won't work as the vector will change positions on each deletion. You'd either have to run it backwards (where there would still be inconsistencies with duplicates) or build an index vector and to the deletion all at once. The deletion all at once is the best method since you won't be resizing the array on each iteration.
Fangjun Jiang
2011 年 7 月 22 日
Good point, thank you! I missed it.
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!