Arrays 如何对结构数组进行排序
如何按项目名称按字母顺序对oo结构数组排序Arrays 如何对结构数组进行排序,arrays,matlab,structure,cell-array,Arrays,Matlab,Structure,Cell Array,如何按项目名称按字母顺序对oo结构数组排序 oo = struct('Item', {'Quill','Ink Pen', 'Pencil'}, 'Cost', {10, 2, 1}) 我尝试使用sort()函数,但没有成功? 谢谢。首先索引您的字段,在本例中是oo.Items,它返回一个逗号分隔的列表。对于字符串数据,使用{}连接到字符串单元格,否则使用[]获取数组: %get the right order using second output of sort [~,index]=sor
oo = struct('Item', {'Quill','Ink Pen', 'Pencil'}, 'Cost', {10, 2, 1})
我尝试使用sort()函数,但没有成功?谢谢。首先索引您的字段,在本例中是
oo.Items
,它返回一个逗号分隔的列表。对于字符串数据,使用{}
连接到字符串单元格,否则使用[]
获取数组:
%get the right order using second output of sort
[~,index]=sort({oo.Item})
%sort it
oo=oo(index)