Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
coding

Subject: coding

From: Jessica

Date: 5 May, 2008 13:54:03

Message: 1 of 2

Hi,

As a simplified example, I am trying to use a loop to fill
in values of a data array as follows:

data = [];
p =input('Enter a number: ');
 
for NumberofCalls = 1:p
data {p,1} = '3';
data{p,2} = '2';
end;


I would like to end up with a matrix when p=2:

3 2
3 2

but instead I get:

[] []

'3' '2'


Is there a way to modify the code to get what I am after?

Thanks!

Subject: coding

From: French Caro

Date: 5 May, 2008 14:03:03

Message: 2 of 2

"Jessica " <jyorzinski@ucdavis.edu> wrote in message
<fvn3hr$di3$1@fred.mathworks.com>...
> Hi,
>
> As a simplified example, I am trying to use a loop to fill
> in values of a data array as follows:
>
> data = [];
> p =input('Enter a number: ');
>
> for NumberofCalls = 1:p
> data {p,1} = '3';
> data{p,2} = '2';
> end;
>
>
> I would like to end up with a matrix when p=2:
>
> 3 2
> 3 2
>
> but instead I get:
>
> [] []
>
> '3' '2'
>
>
> Is there a way to modify the code to get what I am after?
>
> Thanks!
You made a mistake you must use NumberofCalls in your loop :
for NumberofCalls = 1:p
 data {NumberofCalls,1} = '3';
 data{NumberofCalls,2} = '2';
end

and are you sure that you want to put string and to have a
Cell array ?

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us