How can I assign numbers to variables names?

Hi all,
How can I assign numbers to variables names without making them vector elements, for example how we write the following for loop: for i=1:5 Ai=i^2; end in such a way that the result is: A1=1 A2=4 . . A5=25

Antworten (2)

Paulo Silva
Paulo Silva am 15 Mär. 2011

3 Stimmen

That's a very bad idea and there are already several similar questions at matlab answers.

8 Kommentare

Salah Eddine
Salah Eddine am 15 Mär. 2011
than you very much for answering
Oleg Komarov
Oleg Komarov am 15 Mär. 2011
@Salah: accept Paulo's answer if you think he answered your question.
Matt Tearle
Matt Tearle am 15 Mär. 2011
Why does this question keep coming up, I wonder...?
Walter Roberson
Walter Roberson am 15 Mär. 2011
The Endless September perhaps...
Matt Tearle
Matt Tearle am 15 Mär. 2011
Ouch. But seriously, why the sudden glut of virtually identical queries about a ill-advised practice? I've noticed some clumping of topics so far -- passing parameters to function functions, surface plots of vector data, now variables with numeric names. Weird.
Matt Fig
Matt Fig am 15 Mär. 2011
It is almost like we need a FAQ or something...
Matt Fig
Matt Fig am 15 Mär. 2011
I bet if we had just two hyper-linked lines show up somewhere in the process of posting a question, something like:
Are you wondering how to make variables like A1, A2, A3, A4, etc?
Are you wondering why == cannot find your number in an array?
That we could reduce these types of posts significantly. I don't think these two most common FAQs would make the Question submission process that much more cumbersome.
Jan
Jan am 16 Mär. 2011
@Matt: Please send this to Helen (files@mathworks.com). Or better: Let the user confirm, that the question cannot be solved by reading these two links.

Melden Sie sich an, um zu kommentieren.

peter
peter am 15 Mär. 2011

0 Stimmen

arrayfun(@(x) ['A',num2str(x)],[1:10],'uniformoutput',false)

Kategorien

Mehr zu Entering Commands finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 15 Mär. 2011

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by