How to display entries of a vector with exclusion?

조회 수: 1 (최근 30일)
Haoran
Haoran 2014년 3월 20일
댓글: Haoran 2014년 3월 20일
Say I have a vector V, and a set A whose elements are indexes.
How to show elements of V excluding indexes from A?
Example: V={1 4 6 5 8 11 25 36} A = {2 3 6}
I need to display {1 5 8 25 36}.
I know I can make them zero or remove them. But I don't want to do that way because I will use them later, also I want to display several times so it's bad to change the size or those values.
Thank you.

채택된 답변

Viju
Viju 2014년 3월 20일
setdiff(V,V(A))
will give you the vector that you want. This will work when V and A are vectors and not cell arrays (you are using {} which will make V and A a cell array. Use []).|

추가 답변 (1개)

Chandrasekhar
Chandrasekhar 2014년 3월 20일
for i = 1:length(A)
idx = A{i}-i;
V(idx) = [];
end

카테고리

Help CenterFile Exchange에서 Elementary Math에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by