matlab怎么排序数组,如何在MATLAB中排序结构数组?

以下是使用功能

MAX而不必排序的一个示例:

%# First, create a sample structure array:

s = struct('value',{1 7 4},'file',{'img1.jpg' 'img2.jpg' 'img3.jpg'});

%# Next concatenate the "value" fields and find the index of the maximum value:

[maxValue,index] = max([s.value]);

%# Finally, get the file corresponding to the maximum value:

maxFile = s(index).file;

编辑:如果要获得N个最高值,而不是最大值,则可以使用SORT而不是MAX(as Shaka suggested).例如(使用上述结构):

>> N = 2; %# Get two highest values

>> [values,index] = sort([s.value],'descend'); %# Sort all values, largest first

>> topNFiles = {s(index(1:N)).file} %# Get N files with the largest values

topNFiles =

'img2.jpg' 'img3.jpg'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值