From: Vivek Subramanian on 23 Jun 2010 04:27 Hi, I need to sort a n by 2 cell array along the second dimension. The first dimension contains structures and the second dimension contains a numerical value. I want to sort my structures by their corresponding numerical value, so in other words, I want to sort my array by the second dimension. Please let me know if/how this is possible. Thanks in advance!! Vivek
From: Oleg Komarov on 23 Jun 2010 06:06 "Vivek Subramanian" <vas11(a)duke.edu> wrote in message <hvsggr$rj5$1(a)fred.mathworks.com>... > Hi, > > I need to sort a n by 2 cell array along the second dimension. The first dimension contains structures and the second dimension contains a numerical value. I want to sort my structures by their corresponding numerical value, so in other words, I want to sort my array by the second dimension. > > Please let me know if/how this is possible. > > Thanks in advance!! > Vivek So if I am not mistaken you have something like: yourCell = {struct,3;struct,1}; if cellfun('prodofsize',yourCell(:,2)) == 1 [IDX,IDX] = sort(cell2mat(yourCell(:,2))); yourCell = yourCell(IDX,:); end oleg
From: us on 23 Jun 2010 06:12 "Vivek Subramanian" <vas11(a)duke.edu> wrote in message <hvsggr$rj5$1(a)fred.mathworks.com>... > Hi, > > I need to sort a n by 2 cell array along the second dimension. The first dimension contains structures and the second dimension contains a numerical value. I want to sort my structures by their corresponding numerical value, so in other words, I want to sort my array by the second dimension. > > Please let me know if/how this is possible. > > Thanks in advance!! > Vivek can you give an example(?)... us
From: Jan Simon on 23 Jun 2010 12:36 Dear Vivek, Oleg wrote: > yourCell = {struct,3;struct,1}; > > if cellfun('prodofsize',yourCell(:,2)) == 1 > [IDX,IDX] = sort(cell2mat(yourCell(:,2))); > yourCell = yourCell(IDX,:); > end If this is confusing, try this (looking different, but does exactly the same assuming that the numbers in the 2nd column are scalars): [dummy, IDX] = sort([yourCell{:}]); yourCell = yourCell(IDX,:) Jan
|
Pages: 1 Prev: SymHydraulics: temperature effects Next: Writing structs to XML-file |