Importing multiple txt files using a combination of for loop and eval
Show older comments
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.
Accepted Answer
More Answers (0)
Categories
Find more on Characters and Strings in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!