# Matlab - Cell Arrays

Discussion in 'Programmer's Corner' started by Judas543, Apr 2, 2010.

1. ### Judas543 Thread Starter Member

Jan 26, 2010
60
0

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']

2. ### Ghar Active Member

Mar 8, 2010
655
73
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?

3. ### johndoe45 Member

Jan 30, 2010
364
1
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: Apr 2, 2010
4. ### Judas543 Thread Starter Member

Jan 26, 2010
60
0
yea i only know how to do it with numbers :/. Anyway i will keep you posted

5. ### johndoe45 Member

Jan 30, 2010
364
1
1.)

clc
clear all
close all

data = ['Apple ';'Cherry ';'Lime ';'Apricot ';'Chestnut'];
Fruits=cellstr(data)