delete first x number of rows from a cell array
조회 수: 16 (최근 30일)
이전 댓글 표시
I have a 2000*4 cell array. The 4th column is an ascending numeric values from 0 to 30. I do not know how many rows have 0 value in 4th column, and I would like to delete those rows from cell array. I wrote the following code with the loop, which works well. But is there any efficient way to avoid the for-loop?
[m,n]=size(A);
count = 0;
for i=1:m
if isequal(A{i,4},0)
count = count+1;
end
end
A = A(count+1:m,:)
Thank you in advance
댓글 수: 0
채택된 답변
Stephen23
2016년 3월 25일
>> C = num2cell([randi(9,6,3),[0;0;0;1;2;3]])
C =
[5] [8] [6] [0]
[2] [3] [5] [0]
[2] [9] [4] [0]
[3] [4] [8] [1]
[8] [2] [6] [2]
[3] [3] [5] [3]
>> C([C{:,4}]>0,:)
ans =
[3] [4] [8] [1]
[8] [2] [6] [2]
[3] [3] [5] [3]
댓글 수: 0
추가 답변 (1개)
Jos (10584)
2016년 3월 25일
Each cell in the 4th row of A should contain a scalar, being 0 or another value
tf = [A{:,4}] ~= 0
Aout = A(tf,:)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!