Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 如何对结构数组进行排序_Arrays_Matlab_Structure_Cell Array - Fatal编程技术网

Arrays 如何对结构数组进行排序

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结构数组排序

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)