Question

is it possibly to change the order of a cell array randomly with a function, or shoudl I another way around ?

Was it helpful?

Solution

Use randperm:

>> myCell = {'a', 23, [3 4 5], 'bbb'}
myCell = 
    'a'    [23]    [1x3 double]    'bbb'

>> myCell(:) = myCell(randperm(numel(myCell)))
myCell = 
    'bbb'    'a'    [1x3 double]    [23]

This works for n-dimensional cell arrays too:

>> myCell = {1, 2; 'a', 'b'}
myCell = 
    [1]    [2]
    'a'    'b'

>> myCell(:) = myCell(randperm(numel(myCell)))
myCell = 
    [1]    'a'
    'b'    [2]

OTHER TIPS

Perhaps it is as simple as this:

x = {10,11,12}
x(randperm(3))=x
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top