Matlab - sort cell array of objects by property -
suppose had class named foo, datenum property named datetime. if had cell array collection of foo objects, how sort according each object's datetime property?
i have seen references overloading sort method , working arrays of objects, i'm using cell array due dynamic sizing , instructions aren't holding up. got suggestions? cheers
the simplest approach extract time-values vector, sort that, , use new order sort original array.
%# extract datetime cell array foocell datetime = cellfun(@(x)x.datetime, foocell); [~,sortidx] = sort(datetime); %# reorder foocell foocell = foocell(sortidx);
Comments
Post a Comment