3

I have H which is n by n cell array , each cell contains a vector of numbers that I want to sort in ascending order , this is the code that I have tried

   HH = cellfun(@sort,H, 'UniformOutput', false) 

the code worked perfectly but the problem that I want to have the indices of the element of vector,

for example: if a cell in this array contains [ 7 5 6 8] , it will be sorted as [ 5 6 7 8 ] & the indices are [2 3 1 4].

Dan
  • 45,079
  • 17
  • 88
  • 157
joanna
  • 85
  • 1
  • 7

1 Answers1

3

According to Gnovice (Skipping outputs with anonymous function in MATLAB) you can just specify cellfun with two outputs!

[HH, HH_ind] = cellfun(@sort,H, 'UniformOutput', false) 
Community
  • 1
  • 1
Dan
  • 45,079
  • 17
  • 88
  • 157