load multiple .dat files into matlab in matrix form
1 view (last 30 days)
Show older comments
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 Comments
Answers (1)
Guillaume
on 23 Jul 2018
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 Comments
See Also
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!