help with concatenation / eval
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello...
I need to load several files with specific initials and numbers (ex: luc_1.txt to luc_10.txt) to further create variables from each column of those files
Im thinking of using "eval" to create variables, but i dont know how can i get the name of those variables that i've created
im thinking about something like this:
num_part = input ('how many participants do u want to load? ');
num = input ('type the number of trials: ');
np = 1;
for part = np : num_part
np = np+1;
initials = input ('type the initials of the participant: ', 's');
weigth = input ('type the weigth of the participant: ', 's');
n = 1;
for tentativ = n : num
name = [initials,'_',num2str(n)] ;
name_file = [name,'.txt'] ;
load (name_file) ;
n = n+1;
eval([name,'fA = ' name ' (:,1:2) ;'])
eval([name,'fM = ' name ' (:,3:4) ;'])
eval([name,'fV = ' name ' (:,5:8) ;'])
eval([name,'cX = ' name ' (:,9) ;'])
eval([name,'cY = ' name ' (:,10) ;'])
eval([initials,'weigth = ' weigth ' ;'])
end
end
how do i get the name of those variables tht i' created w/ eval? any suggestions?
thx :)
0 Kommentare
Akzeptierte Antwort
Jos (10584)
am 8 Jan. 2014
Avoid eval!
You want to use cell or structs. For example:
initials = 'AB'
weight = '171 lb'
for n = 1:3
name_file = [initials '_' num2str(n) '.txt'] ;
RAWDATA = load(name_file) ;
data.(initials).values(n).fA = RAWDATA(:,1:2) ;
data.(initials).values(n).fM = RAWDATA(:,3:4) ;
end
data.(initials).weight = weight ;
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Cell Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!