MATLAB: Importing multiple txt files using a combination of for loop and eval

data importfor loopMATLAB

Hello.
I have .txt files with some texts (name of variables on the first row) and numbers, so I can't use "load". I would like to extract just numbers in text files (result1.txt, result2.txt … result50.txt) at once.
If I do…
for i=1:50
eval(['txtfile' num2str(i) '= importdata(result' num2str(i) '.txt)']);
end
I get an error message "Undefined variable "result1" or class "result1.txt"". Even if I place ' ' or " " like
eval(['txtfile' num2str(i) '= importdata('result' num2str(i) '.txt')']);
and
eval(['txtfile' num2str(i) '= importdata("result' num2str(i) '.txt")']);,
neither of them works. What should I do? Any suggestions are appreciated.

Best Answer

Don't use evil eval for this...see the FAQ (there's also examples in the doc's now)