How to load multiple indexed .txt tables at once using a loop?
3 次查看(过去 30 天)
显示 更早的评论
MOTIVATION: Hi, I want to import multiple tables such as table1.txt, table2.txt, ..., tablei.txt.
WHAT I DID: For this I wrote the following lines:
for i=1:3;
x{i}=load('table%d.txt',i)';
end
PROBLEM: I obtain the following error: ??? Error using ==> load Argument must contain a string.
QUESTION How should I write the command lines to obtain
x1=load('table1.txt');
x2=load('table2.txt');
xi=load('tablei.txt');
without needing to write each line for each i?
I thank you in advance for your help
Emerson
0 个评论
采纳的回答
TAB
2012-1-18
for i=1:3
x{i}=load(sprintf('table%d.txt',i));
end
Why you are using load() for reading text file ? You can do better with textscan().
2 个评论
TAB
2012-1-19
You can use textscan() based on what is content of your text file and what is your expected output.
For help type
>> doc textscan
on command window
Please give some example data of your text file and your expected output, then only i can suggest anything.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Files 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!