例如,我有一个牢房:
c = { {'c1_str1','c1_str2'},{'c2_str1','c2_str2','c2_str3','c2_str4'}, {'c3_str1','c3_str2'}我想过滤c以获取cc单元格:
cc = {'c1_str2', 'c2_str2','c2_str3','c2_str4', 'c3_str2'} 换句话说,我希望每个子单元格d c保留除第一个元素之外的所有元素。
我试过:
cc = cellfun(@(x)[x{2:end}],c,'UniformOutput',0);
cc = cellfun(@(x)[x(2:end)],c,'UniformOutput',0); 但没有成功。由于c足够大,请您提出一个建议,我们如何使用cellfun避免循环实现:
cc = {};
for i = 1:numel(c)
cc= [cc c{i}(2:end)];
end谢谢!
PS:,任何将子单元格保持在任意位置的建议(例如,第一、第二和第五个子单元格),这将是非常有趣的。
发布于 2014-08-08 18:48:19
你差点就有了:
cc = cellfun(@(x) x(2:end),c,'UniformOutput',0);
cc = [cc{:}]任意的版本有点棘手:
idx = [1,2,5]
cc = cellfun( @(x) x( idx(idx<=numel(c)) ),c,'uni',0 )
cc = [cc{:}]https://stackoverflow.com/questions/25210177
复制相似问题