remove rows with certain element in cell arrays
조회 수: 4 (최근 30일)
이전 댓글 표시
In the following data set, I want to keep only the rows with 'Hourly' element, thus only row 2. I use the following, but it doesn't work. Can anybody help me?
data={'s' 'e' 'daily'; 't' 'c' 'hourly'; 'm' 'b' 'daily'}
data_2 = cellfun(@(x) x(x(:,3)=='Hourly'), data, 'UniformOutput', false)
댓글 수: 0
채택된 답변
Geoff
2012년 2월 2일
Did you mean to write:
x{:,3}=='Hourly'
The curly-braces thing trips me up all the time =)
댓글 수: 2
추가 답변 (1개)
Jan
2012년 2월 2일
data = {'s' 'e' 'daily'; ...
't' 'c' 'hourly'; ...
'm' 'b' 'daily'};
data2 = data(strcmpi(data(:, 3), 'hourly'), :);
참고 항목
카테고리
Help Center 및 File Exchange에서 Cell Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!