eleminating data from a long vector
古いコメントを表示
Hi all!
i have an index vector:
%
index=[id1;id2;id3.....idn]
and i have a long vector: A
i want to eleminate the elment of the vector a which have the index in index in this way:
%
A(id1:id1+30)=[]
A(id2:id2+30)=[]
.
.
.A(idn:idn+30)=[]
how could i write this in matlab in a compact manner?
thank you
1 件のコメント
Walter Roberson
2013 年 2 月 19 日
Are you certain this is what you want to do? After the first removal, everything from id1+30 onward in the vector would "fall down" 31 places. Does id2 take that renumbering into account?
採用された回答
その他の回答 (1 件)
Andrei Bobrov
2013 年 2 月 19 日
A=1:1000; % Example
index=[10 100 500];
n = 30;
A(bsxfun(@plus,index,(0:n-1)'))=[];
3 件のコメント
Walter Roberson
2013 年 2 月 19 日
Should either be n=31 or run from 0:n instead of 0:n-1 as the original question asks to delete id1:id1+30 which is 31 locations.
Jan
2013 年 2 月 19 日
But in general this method is faster than the arrayfun and cell2mat approach.
Rica
2013 年 2 月 19 日
カテゴリ
ヘルプ センター および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!