Matlab - Cell Arrays

Thread Starter

Judas543

Joined Jan 26, 2010
60


I have no clue on what to do here. I need help on steps 2, 3, and 4.
it seems rand or randperm only works with numeric number so for the life of me i cant figure out how to put
random values of Fruits into the CellFun

clear %clear workspace
clc %clear command window

Fruits = {'Apple';'Cherry';'Lime';'Apricot';'Chestnut'}
CellFun = cell(5,5)

numR = ['random 1','random 2';'random 3','random 4']
 

Ghar

Joined Mar 8, 2010
655
You're not making random fruit, you're putting the fruit in random positions.

How do you assign a fruit to a position?

CellFun(2) = 'Apricot' for example.

Which number in that statement should be random?
 

johndoe45

Joined Jan 30, 2010
364
a position in the cell would be like x(4*rand+1,4*rand+1)

this is the scalar x at a random number from 1-5 x random number from 1-5

here is my theory. start off with 5 x 5 cell of 1's

then make apple(4*rand+1,4*rand+1) and multiply with dot in front so like this
.*

and do this for the other fruits.

finally make if statement
if x==1 %need two equal signs
x=[]
end


THIS IS CORRECT WAY TO DO THIS. I DON'T KNOW HOW TO USE LETTERS JUST NUMBERS. SO PLEASE POST YOUR FINAL SOLUTION SO I CAN LEARN TOO!!!!!
 
Last edited:
Top