Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
![]() |
#1 |
高级会员
注册日期: 2019-11-21
帖子: 3,006
声望力: 66 ![]() |
![]()
我正在使用在MATLAB中使用颜色直方图交集的图像检索系统。此方法提供了以下数据:代表直方图相交距离的实数和图像文件名。因为它们是不同的数据类型,所以我将它们存储在具有两个字段的结构数组中,然后将此结构保存在.mat文件中。现在,我需要根据直方图相交距离以降序对这种结构进行排序,以便检索具有最高直方图相交距离的图像。我尝试了许多方法来对这些数据进行排序,但是没有结果。请您能帮我解决这个问题吗?
回答: 以下是使用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( 如Shaka建议 )。例如(使用上面的结构): >> 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' 更多&回答... |
![]() |
![]() |