How to delete cell entries with an index vector
조회 수: 5 (최근 30일)
이전 댓글 표시
Dear community,
I have a cell
A=cell(m,n)
and a logical vector
b=(m,1)
containing logical ones and zeros (true, false). What I like to do now is to delete the cell entries, if there is a logical one
A(b,:)=[];
But the error is: Index of element to remove exceeds matrix dimensions. What have I done wrong?
Thanks a lot!
댓글 수: 0
답변 (3개)
Azzi Abdelmalek
2014년 1월 10일
n=3;
m=6;
A=num2cell(rand(m,n))
idx=[1 0 0 1 1 0]
A(logical(idx),:)=[]
댓글 수: 0
Simon
2014년 1월 10일
Hi!
Are you sure that b is not longer than size(1) of A? Is b really a logical vector with true or false? I have no problem if I use
n=3
m=5
A=cell(m,n)
b=false(m,1)
b(2) = true
b(5) = true
A(b,:)=[]
An error is thrown for
A=cell(m,n)
b(6) = true
A(b,:)=[]
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!