From: us on 2 Apr 2010 17:47 "Judas Magnus" <ragnaork5435(a)yahoo.com> wrote in message <hp5nsc$jvp$1(a)fred.mathworks.com>... > 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 one of the solutions f=cellstr(char('m','c','p','d','r')); cf=cell(5,5); r=randperm(numel(cf)); r=r(1:numel(f)); cf(r)=f(randperm(numel(f))) %{ % C = % <- based on current RAND state... [] [] 'd' [] [] [] [] [] 'c' [] [] [] [] [] [] [] 'r' 'p' [] [] [] [] [] 'm' [] %} us |