How to read data from different text file in a loop, save in a matrix and plot??
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Khan Md Shafi Ahad Siddique
le 12 Avr 2017
Modifié(e) : Stephen23
le 4 Mai 2021
Hello,
For example I have different data file named data1.txt, data2.txt, data3.txt... etc. Now I want to read the data from each text file one by one using a loop and save them in a matrix and then plot. I'm out of my depth here.
Any help would be very much appreciated. Thanks..!!
0 commentaires
Réponse acceptée
KSSV
le 12 Avr 2017
Modifié(e) : KSSV
le 12 Avr 2017
A regular google will give you ton's of sites. This topic is discussed to death in mathworks.
dinfo = dir('*.txt'); % get the text files from folder
for K = 1 : length(dinfo)
thisfilename = dinfo(K).name; %just the name
%load this file
% thisdata = load(thisfilename);
end
plotting, reading the file depends on how your text file is.
0 commentaires
Plus de réponses (1)
Stephen23
le 12 Avr 2017
Modifié(e) : Stephen23
le 4 Mai 2021
If you want to import the files in alphanumeric order than you could download my FEX submission natsortfiles, and use the examples to base your code on:
P = 'C:\Test'; % directory path
S = dir(fullfile(P,'data*.txt'));
S = natsortfiles(S);
for k = 1:numel(S)
F = fullfile(P,S(k).name)
... your code here
end
0 commentaires
Voir également
Catégories
En savoir plus sur Workspace Variables and MAT-Files 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!