Reading multiple txt data
Mostra commenti meno recenti
Hello
I am a kinda newbie in matlab and want to know how to read multiple txt-files in my function. I am using Matlab R2017a, windows 10.
Whole code below. It is reading only 1 txt-file(last one), but i want to read all 74 files
txtfiles = dir('C:\Users\User\Documents\MATLAB\signal\signal*.txt');
ttrigger = dir('C:\Users\User\Documents\MATLAB\signal\trigger*.txt');
N = length(txtfiles) ;
for k = 1:N
thisfile = txtfiles(k).name ;
Tthisfile = ttrigger(k).name;
s = csvread(thisfile);
t = csvread(Tthisfile);
r=0;
j=1;
n=0;
loc=0;
q=0;
lock=0;
inPulseS=false;
inPulseT=false;
for i=1:length(s)
if t(i)>3 && inPulseT==false
n=n+1;
loc(n)=i;
inPulseT=true;
elseif t(i)<3
inPulseT=false;
end
if s(i)<=-5 && inPulseS==false
q=q+1;
lock(q)=i;
inPulseS=true;
elseif s(i)>-5
inPulseS=false;
end
end
g=1;
for v=1:length(loc)-1
next=lock(lock>loc(v) & lock<loc(v+1));
if length(next)==1
diff(g)=next-loc(v);
g = g+1;
end
end
filter=diff(diff>100 & diff<400);
kk=0;
rr=1;
for h=1:length(filter)-1
if filter(h)<200
kk(rr)=0;
rr=rr+1;
else
kk(rr)=1;
rr=rr+1;
end
end
end
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su File Operations in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!