Error when trying to remove rows with specific values from cell array.
조회 수: 6 (최근 30일)
이전 댓글 표시
I have a cell array that looks like this with strings and numbers

I'm trying to write simple code that will remove entire rows in the array if numbers 1-20 are present in column 1:
toremove = [1:20];
event_time(ismember(event_time(:,1),toremove)) = [];
However I receive this error when I run my code
Error using cell/ismember
Input A of class cell and input B of class double must be cell arrays of character vectors, unless one is a character vector.
How would I index event_time by the numbers in column 1? They are not strings/characters so strcmp does not work, and treating them as integers, as above does not work either. Many thanks!
댓글 수: 0
채택된 답변
Star Strider
2020년 11월 7일
Try this:
CA = num2cell(randi(50, 25, 5)); % Create Cell Array
idx = cellfun(@(x)ismember(x, 1:20), CA(:,1)); % Logical Vector Selecting (1:20) In Column #1
CAedited = CA(~idx,:); % Eliminat Rows Meeting Criteria
Use your own cell array for ‘CA’.
댓글 수: 6
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!