load multiple .dat files into matlab in matrix form

1 visualizzazione (ultimi 30 giorni)
Ernest Adisi
Ernest Adisi il 23 Lug 2018
Risposto: Guillaume il 23 Lug 2018
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

Risposte (1)

Guillaume
Guillaume il 23 Lug 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.

Categorie

Scopri di più su Data Import and Analysis in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by