How to sort structure arrays in MATLAB?

后端 未结 2 1788
北恋
北恋 2021-02-14 07:55

I\'m working with an image retrieval system using color histogram intersection in MATLAB. This method gives me the following data: a real number which represents the histogram i

2条回答
  •  一生所求
    2021-02-14 08:44

    It's also possible to sort the entire structure.

    To build off of gnovice's example...

    % Create a structure array
    s = struct('value',{1 7 4},'file',{'img1.jpg' 'img2.jpg' 'img3.jpg'});
    
    % Sort the structure according to values in descending order
    % We are only interested in the second output from the sort command
    
    [blah, order] = sort([s(:).value],'descend');
    
    % Save the sorted output
    
    sortedStruct = s(order);
    

提交回复
热议问题