MATLAB: Sort a structure sortstructure Is it possible to create a structure that holds the following information: id_number length such that I can then sort the structure by length from largest to smallest. I then want to retrieve the id_number for the top 5 elements. Best Answer something like:s = struct('id_number', mat2cell(1:100, 1, ones(100, 1)), 'length', mat2cell(rand(1, 100), 1, ones(100, 1)));[a, b] = sort([s.length]);[s(b(1:5)).id_number] Related SolutionsMATLAB: Creating multidimentional structures s = struct('f1', num2cell(rand(100)), 'f2', 25);You'll need 10000 data points. Above you provided 200. MATLAB: How to sort matrices in side structure [ii,~] = cellfun(@size,{clust.Data});[~,jj] = sort(ii);clust = clust(jj); Related QuestionExtracting information from structer under specific conditionsHow to sort one field of a structure based on the values of another fieldCombine 3x3D into 4D matrixSort fields of struct by length and alphabetically
Best Answer