remove rows with certain element in cell arrays
3 次查看(过去 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!