单元格数组文本操作

时间:2017-10-12 19:03:41

标签: matlab cell-array

我只需要保留单元格数组中第n个位置之后的元素。

示例:

def num():
    x= []
    for y in range (-100,100):
        z = (16+y**2)**0.5 
        if z % 1 == 0:
            x.append(z)
    return(x)

我需要得到这个结果:

cell_in = {'test string no (1)'; 
           'test string no (2)'; 
           'test string no (3)'}

我尝试了以下失败的方法:

cell_out = {'no (1)'; 
            'no (2)'; 
            'no (3)'}

有没有办法对此进行排序,可能使用cell_out = cell_in{:}(13:end)

1 个答案:

答案 0 :(得分:1)

您无法直接将索引应用于所有单元格的内容。

实现您想要的方法是使用cellfun通过anonymous function将所需的索引应用于所有单元格的内容:

cell_out = cellfun(@(c) c(13:end), cell_in, 'UniformOutput', false);