Matlab 인덱스 관련 질문입니다.

okabe의 이미지


매트랩에서 인덱스를 이용하는것을 공부하고있는데요

어디에서도 찾아 볼수 없어서 질문드립니다.

만약에 A=[1,2,3,4,5] 이고 B=[2,3]

이라면 A에서 B에 해당되는것을 빼고 싶은데요

즉 A=[1,4,5] 이 결과를 얻고 싶은데 어떻게 해야할지 알고 싶습니다.

매트랩 사이트와 관련사이트는 일정 부분만을 선택해서 데이터를 빼오는 밖에 없더라고요

조언 부탁드립니다 ㅠ_ㅠ

qiiiiiiiip의 이미지

setdiff(A,B)

>> help setdiff
 SETDIFF Set difference.
    SETDIFF(A,B) when A and B are vectors returns the values
    in A that are not in B.  The result will be sorted.  A and B
    can be cell arrays of strings.
 
    SETDIFF(A,B,'rows') when A are B are matrices with the same
    number of columns returns the rows from A that are not in B.
 
    [C,I] = SETDIFF(...) also returns an index vector I such that
    C = A(I) (or C = A(I,:)).
 
    See also UNIQUE, UNION, INTERSECT, SETXOR, ISMEMBER.
 
    Overloaded methods:
       opaque/setdiff
       cell/setdiff
       ordinal/setdiff
       categorical/setdiff
       nominal/setdiff
 
    doc setdiff
bushi의 이미지

A=[1 2 3 4 5]
B=[2 3]
A(B)=[]

ocatve 에선 돌아갑니다. http://weboctave.mimuw.edu.pl/weboctave

B[] 에 있는 것들이 제거하고 싶은 index 들인지 아니면 value 들인지 질문이 애매한데요.

qiiiiiiiip의 이미지

그러게요. B에 있는 것이 index라면 bushi님의 답글을,
B에 있는 것이 value라면 setdiff를 쓰시면 되겠네요..
인덱스를 언급하신걸보니, 전자인것 같네요..

>> A=[4 5 6 7 8]; B=[4 5];
>> setdiff(A,B)
 
ans =
 
     6     7     8
 
>> A(B)=[]
 
A =
 
     4     5     6