Search code examples
arraysmatlabpositioncell-array

Change the position of elements in cell array (Matlab)


I have an initial cell array : cell={'AB' 'CD' 'EF'}. How could I generate all of the cellarrays which their elements are combined from the changing positions of each element in the initial cell array?

The expected output in this case should be:

          out1 = {'AB' 'CD' 'EF'}
          out2 = {'AB' 'EF' 'CD'}
          out3 = {'CD' 'AB' 'EF'}
          out4 = {'CD' 'EF' 'AB'}
          out5 = {'EF' 'AB' 'CD'}
          out6 = {'EF' 'CD' 'AB'}

Thank you !


Solution

  • This is my answer inspired by excaza's comment

    perms(cell)