eleminating data from a long vector
조회 수: 1 (최근 30일)
이전 댓글 표시
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?
채택된 답변
Azzi Abdelmalek
2013년 2월 19일
편집: Azzi Abdelmalek
2013년 2월 19일
A=rand(1,1000); % Example
index=[10 100 500]
idx=arrayfun(@(x) x:x+30,index,'un',0);
A(cell2mat(idx))=[]
댓글 수: 2
Walter Roberson
2013년 2월 19일
This is not equivalent to the original sequence in that the original sequence does not delete id2:id2+30 until after id1:id1+30 are gone, so in absolute locations it might need to add 31 more for the 2nd index, 62 for the 3rd, and so on... depending on the sort order of the indices.
Azzi Abdelmalek
2013년 2월 19일
편집: Azzi Abdelmalek
2013년 2월 19일
I don't think that what he meant by the sequence. I guess he want to remove them at the same time.
추가 답변 (1개)
Andrei Bobrov
2013년 2월 19일
A=1:1000; % Example
index=[10 100 500];
n = 30;
A(bsxfun(@plus,index,(0:n-1)'))=[];
댓글 수: 3
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!