Excluding some elements from a Vector

qw=[1:0.4:50]';
c=[9,17,25, 31,43]'
I wish to exclude all the elements that are c-0.5 to c+0.5

 채택된 답변

Oleg Komarov
Oleg Komarov 2011년 4월 22일

0 개 추천

qw = 1:0.4:50;
c = [9;17;25;1;43];
tol = .5;
(a) Bsxfun solution
Out = qw(~any(bsxfun(@ge, qw, c-tol) & bsxfun(@le, qw, c+tol)));
(B) Arrayfun solution
Out = qw(~arrayfun(@(x) any(x >= c-tol & x <= c+tol),qw))

댓글 수: 3

Sindhu Kaimal
Sindhu Kaimal 2011년 4월 22일
I wish to exclude all the points that are (c to c+0.5) and from (c-0.5 to c). For example all points from 8.5- 9.5 and so on...
Oleg Komarov
Oleg Komarov 2011년 4월 22일
So, did you try the code? Now, (b) solution also is consistent with (a)
Sindhu Kaimal
Sindhu Kaimal 2011년 4월 22일
Yes, thanks

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Splines에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by