Matlab - sort an array of arrays of objects by property

Suppose I had a class named Foo with a datenum property named DateTime. If I had a collection of arrays of Foo objects, how would I sort them according to each property of the DateTime of the object?

I saw links to overloading the sorting method and working with arrays of objects, however I use an array of cells due to dynamic size, and these instructions do not hold. Anyone have any suggestions? Greetings

+4
source share
1 answer

The easiest way is to extract temporary values ​​into a vector, sort it, and use the new sort order of the original array.

%# extract DateTime from the cell array fooCell dateTime = cellfun(@(x)x.DateTime, fooCell); [~,sortIdx] = sort(dateTime); %# reorder fooCell fooCell = fooCell(sortIdx); 
+4
source

Source: https://habr.com/ru/post/1480408/


All Articles