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:
Creating variables

Subject: Creating variables

From: Lorenzo

Date: 16 Jun, 2009 08:24:14

Message: 1 of 5

Hi everybody! I've got this problem: I need to create a suqence of variables (of which I know the values) having sequencial names. For example I have to create variables named A1, A2, A3... and I need to assing to each one it's value. I could use the strcat('A', int2str(i)) command where i=1,2,3... but once I do that, I have the string A1, A2, A3 and how can I create variables A1=10, A2=100 A3=455 strarting from this?

I hope I made myself clear...

Thanx

Subject: Creating variables

From: Darren Rowland

Date: 16 Jun, 2009 09:16:01

Message: 2 of 5

Lorenzo <liquidcrystal@tiscali.it> wrote in message <17446007.750.1245140686052.JavaMail.jakarta@nitrogen.mathforum.org>...
> Hi everybody! I've got this problem: I need to create a suqence of variables (of which I know the values) having sequencial names.
<snip>
>
> I hope I made myself clear...

Your problem is quite clear, but why do you need to do this? What is wrong with the current variable names?
Further what will you gain by this change?

If you really need to change the names, try to put the variables into a vector A, that way when you want A1 = 10 in your code you just type
A(1) = 10
instead, which is just as readable, and much more flexible.
Hth
Darren

Subject: Creating variables

From: Loren Shure

Date: 16 Jun, 2009 11:16:22

Message: 3 of 5

In article
<17446007.750.1245140686052.JavaMail.jakarta@nitrogen.mathforum.org>,
liquidcrystal@tiscali.it says...
> Hi everybody! I've got this problem: I need to create a suqence of variables (of which I know the values) having sequencial names. For example I have to create variables named A1, A2, A3... and I need to assing to each one it's value. I could use the strcat('A', int2str(i)) command where i=1,2,3... but once I do that, I have the string A1, A2, A3 and how can I create variables A1=10, A2=100 A3=455 strarting from this?
>
> I hope I made myself clear...
>
> Thanx
>

Perhaps use a struct instead with the names you want as fieldnames. Or
use cell arrays. Read this FAQ entry for background:

http://matlabwiki.mathworks.com/MATLAB_FAQ#How_can_I_create_variables_A1
.2C_A2.2C....2CA10_in_a_loop.3F

--
Loren
http://blogs.mathworks.com/loren

Subject: Creating variables

From: Lorenzo

Date: 17 Jun, 2009 09:35:48

Message: 4 of 5

The problem is related to the fact that I don't need to create simple variables like A=1 but I need to create some matrices every each one with a different sequencial name


I'm looking to the structures

Subject: Creating variables

From: Loren Shure

Date: 17 Jun, 2009 11:16:37

Message: 5 of 5

In article
<17906239.6790.1245231378580.JavaMail.jakarta@nitrogen.mathforum.org>,
liquidcrystal@tiscali.it says...
> The problem is related to the fact that I don't need to create simple variables like A=1 but I need to create some matrices every each one with a different sequencial name
>
>
> I'm looking to the structures
>

Why? Why can you not store them as a sequence in a cell array? Or have
them in a struct with the field names being the sequential names?


--
Loren
http://blogs.mathworks.com/loren

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