MATLAB Answers

How to read data from different text file in a loop, save in a matrix and plot??

조회 수: 11(최근 30일)
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

댓글을 달려면 로그인하십시오.

채택된 답변

KSSV
KSSV 12 Apr 2017
편집: KSSV 12 Apr 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

댓글을 달려면 로그인하십시오.

추가 답변(1개)

Stephen Cobeldick
Stephen Cobeldick 12 Apr 2017
If you want to import the files in the correct order than you can download my FEX submission natsortfiles, and use the examples to base your code on:
D = 'C:\Test'; % directory path
S = dir(fullfile(D,'data*.txt'));
N = natsortfiles({S.name});
for k = 1:numel(N)
fnm = fullfile(D,N{k})
... your code here
end

  댓글 수: 0

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by