load multiple .dat files into matlab in matrix form
1 次查看(过去 30 天)
显示 更早的评论
I have a folder of N .dat files that I want to load in matrix form. They all have the filename form B000XX.dat where XX are changing. How can I accomplish this please. This code is wrong but i know it should be along the lines of this.
clear all
clc
importdata=['Cam_B_ds'];
for k=1:50
importdata=[importdata dlmread(sprintf('B000xx.dat',k))]
end
0 个评论
回答(1 个)
Guillaume
2018-7-23
You need to read the documentation of sprintf to learn how you actually specify how data is to be inserted:
sprintf('B000%02d.dat', k)
It is very likely that your
importdata = [importdata, dlmread(sprintf('B000%02d.dat', k))]; %Added a comma for clarity
will not do what you want but you haven't really explained what you intended to do with that line. And certainly, initialising importdata with a char array as in:
importdata = 'Cam_B_ds'; %brackets removed as they didn't anything except slow the code.
is certainly wrong. No idea what the intent is behind that.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!