标签: string matlab sorting cell-array
我在matlab中有字符串的单元格数组。我想按字母顺序对每个字符串中的字母进行排序。我怎么能这样做?
例如,如果我有['dcb','aetk','acb'}],我希望它是:['bcd','aekt','abc']。
['dcb','aetk','acb'}]
['bcd','aekt','abc']
答案 0 :(得分:3)
这里方便的助手是cellfun,有非标量输出的正确选项 - 我们告诉它依次在单元格数组的每个元素上运行sort:
cellfun
sort
>> a = {'dcb' 'aetk' 'acb'} a = { [1,1] = dcb [1,2] = aetk [1,3] = acb } >> b = cellfun(@sort, a, 'UniformOutput', false); b = { [1,1] = bcd [1,2] = aekt [1,3] = abc }