MATLAB: Could anyone help me how to select the partitions in a random manner.

random selection

Code:
X=[3];
A = partitions(X)
partdisp(A)
when i run the code it executes and gives the result in the following manner.
A = {1×1 cell}
{1×2 cell}
{1×2 cell}
{1×2 cell}
{1×3 cell}
The 5 partitions of set {1 2 3}:
{1 2 3}
{1 2} {3}
{1 3} {2}
{1} {2 3}
{1} {2} {3}
Among 5 partitions i want to select any one partition in a random manner.
So i tried with the following command rand(A)
But i got the error stating Size inputs must be numeric.
As each partition contains the set it's not in numeric form.I can understand it.But there should be some way of selecting it.
As i couldnt able to do it,coud anyone help me to solve it.

Best Answer

N = length(A) ;
idx = randperm(N,1) ;
iwant = A{idx}
Related Question