A script to load multiple (n) txt files and save them into a single matrix of n columns

7 vues (au cours des 30 derniers jours)
Sorry for disturbing with this basic question, but I am new in MATLAB. I have been using OriginLab for many years. Importing data and copying individual columns into a single large matrix was very easy. It seems like impossible now.
I have a folder with several files, lets say 15, saved as a text file. The text file contains a heading to be removed, starting from row 6. The file itself is simply time and amplitude from the oscilloscope. I need to load the files and paste them into one single matrix. Only first column would be time, the rest are the amplitude data.
Any tips to generate a script to automate that? using the import function does it only for one file. When doing it again overwrites the values.
Thanks in advance

Réponse acceptée

KSSV
KSSV le 15 Mar 2017
F = dir('*.txt'); % you are in the folder of text files
NF = length(F) ; % number of files
data = cell(N,1) ;
for i = 1:length(F)
thisdata = importdata(F(i).name) ;
% pick your data from here
data{i} = thisdata.data ;
end
Later you can convert your cells into matrix using cell2mat. Or you can initialize, your matrix and kepp adding the column inside the loop.

Plus de réponses (1)

ARP
ARP le 15 Mar 2017
Thanks for the quick answer, but I don't have enough background to make it work
  1 commentaire
KSSV
KSSV le 15 Mar 2017
Not a problem...copy this code and run it. It is easy. MATLAB is user friendly.

Connectez-vous pour commenter.

Catégories

En savoir plus sur File Operations dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by