在Matlab中按字母顺序混合字符串的字母 [英] Mix letters of a string in alphabetical order in matlab

查看:132
本文介绍了在Matlab中按字母顺序混合字符串的字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在matlab中有字符串的单元格数组.我想按字母顺序对每个字符串中的字母进行排序.我该怎么办?

I have the cell array of strings in matlab. I want to sort letters in every string in alphabetical order. How can I do that?

例如,如果我有['dcb','aetk','acb'}],我希望它是:['bcd','aekt','abc'].

For example, if I have ['dcb','aetk','acb'}], I want it to be: ['bcd','aekt','abc'].

推荐答案

这里的便捷帮助器是 cellfun ,具有用于非标量输出的正确选项-我们告诉它运行

The handy helper here is cellfun, with the correct option for nonscalar output - we tell it to run sort on each element of the cell array in turn:

>> 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
}

这篇关于在Matlab中按字母顺序混合字符串的字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆