필터 지우기
필터 지우기

help with concatenation / eval

조회 수: 1 (최근 30일)
lucas
lucas 2014년 1월 8일
댓글: lucas 2014년 1월 8일
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 :)

채택된 답변

Jos (10584)
Jos (10584) 2014년 1월 8일
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 ;
  댓글 수: 1
lucas
lucas 2014년 1월 8일
hey Jos! thx for the help! But i never studied those structs stuff before!
I need to create a .txt with some calculations w/ those columns of each file
can i create a single .txt for all the participants, like:
fA.txt:
luc_1.txt luc_2.txt joe_5.txt bob_3.txt
data data data data
or something like this
luc_1_fA.txt, luc_2_fA.txt, joe_5_fM.txt.....
?
thanks :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by