From: Judas Magnus on
say that I have a string like this:
Foods= char('Meat','Chicken','Pork','Duck','Roast')
frCell = cellstr(Foods)

I want to create a 5 x 5 cell array called cArray containing at 5 random positions the cells of Foods.

I know I can create a 5x5 array by cell(5,5) but how can i randomize positions of the frCell into the cArray
From: Matt Fig on
Look at using the output from randperm as an index into the array.
From: us on
"Judas Magnus" <ragnaork5435(a)yahoo.com> wrote in message <hp5kl8$218$1(a)fred.mathworks.com>...
> say that I have a string like this:
> Foods= char('Meat','Chicken','Pork','Duck','Roast')
> frCell = cellstr(Foods)
>
> I want to create a 5 x 5 cell array called cArray containing at 5 random positions the cells of Foods.
>
> I know I can create a 5x5 array by cell(5,5) but how can i randomize positions of the frCell into the cArray

one of the solutions
- if more than one instance is allowed...

f=cellstr(char('m','c','p','d','r'));
rf=ceil(numel(f)*rand(size(cf)));
cf=f(rf)
%{
% CF = % <- based on current RAND state(!)...
'p' 'm' 'm' 'm' 'r'
'd' 'd' 'r' 'd' 'd'
'd' 'm' 'c' 'r' 'd'
'r' 'c' 'c' 'm' 'p'
'd' 'c' 'c' 'r' 'm'
%}

us
From: us on
"Judas Magnus" <ragnaork5435(a)yahoo.com> wrote in message <hp5kl8$218$1(a)fred.mathworks.com>...
> say that I have a string like this:
> Foods= char('Meat','Chicken','Pork','Duck','Roast')
> frCell = cellstr(Foods)
>
> I want to create a 5 x 5 cell array called cArray containing at 5 random positions the cells of Foods.
>
> I know I can create a 5x5 array by cell(5,5) but how can i randomize positions of the frCell into the cArray

something was missing in the last reply(!)...
sorry for confution...

one of the solutions
- if more than one instance is allowed...

f=cellstr(char('m','c','p','d','r'));
cf=cell(5,5); % <- pre-allocate(!)...
rf=ceil(numel(f)*rand(size(cf)));
cf=f(rf)
%{
% CF = % <- based on current RAND state(!)...
'p' 'm' 'm' 'm' 'r'
'd' 'd' 'r' 'd' 'd'
'd' 'm' 'c' 'r' 'd'
'r' 'c' 'c' 'm' 'p'
'd' 'c' 'c' 'r' 'm'
%}

us
From: Judas Magnus on
How can i limit the size to take only 5 cell containers. Right now its completely filling my array with those meats

"us " <us(a)neurol.unizh.ch> wrote in message <hp5nj1$fqt$1(a)fred.mathworks.com>...
> "Judas Magnus" <ragnaork5435(a)yahoo.com> wrote in message <hp5kl8$218$1(a)fred.mathworks.com>...
> > say that I have a string like this:
> > Foods= char('Meat','Chicken','Pork','Duck','Roast')
> > frCell = cellstr(Foods)
> >
> > I want to create a 5 x 5 cell array called cArray containing at 5 random positions the cells of Foods.
> >
> > I know I can create a 5x5 array by cell(5,5) but how can i randomize positions of the frCell into the cArray
>
> something was missing in the last reply(!)...
> sorry for confution...
>
> one of the solutions
> - if more than one instance is allowed...
>
> f=cellstr(char('m','c','p','d','r'));
> cf=cell(5,5); % <- pre-allocate(!)...
> rf=ceil(numel(f)*rand(size(cf)));
> cf=f(rf)
> %{
> % CF = % <- based on current RAND state(!)...
> 'p' 'm' 'm' 'm' 'r'
> 'd' 'd' 'r' 'd' 'd'
> 'd' 'm' 'c' 'r' 'd'
> 'r' 'c' 'c' 'm' 'p'
> 'd' 'c' 'c' 'r' 'm'
> %}
>
> us