How to set up dynamic naming of vectors?

2 visualizzazioni (ultimi 30 giorni)
LETS SAY:
I have a large matrix of unknown size in a text file.
I wish to import it column by column and store each column as a vector.
I wish to name the vectors something like data1,data2,data3,...etc.
================
QUESTION:
How to dynamically name vectors I am creating?
I obviously need to use a loop but how do I set a naming condition?
Z = dlmread('file.txt') %import file in to matrix Z
a = length(Z(1,:)) %acquire number of columns
for N = 1:a
'data+N' = Z(:,N) %obviously wrong but how do I make matlab understand?
end
THANK YOU!

Risposta accettata

Walter Roberson
Walter Roberson il 12 Ott 2012
  5 Commenti
sono
sono il 12 Ott 2012
Well I got it to work so I think I am good but in response to your comment I do want to mention the guide he linked condemns using EVAL :)
"Repeat: don't create variables at runtime using EVAL unless you have a very good reason, such as someone gives you a MAT file with 2000 variables named A1428, for example. Even in that case, you can avoid EVAL"
Walter Roberson
Walter Roberson il 12 Ott 2012
Nathaniel was poking fun at me ;-)

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by