Why textread in MATLAB error?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
clear all
close all
listf=dir('E:\New folder (5)\data\*.txt');
n=length(listf);
for i=1:n
filename=listf(i).name;
data{i}=textread(filename);
end
fs=1000;
fcc=60;
fc=(((fcc*2*pi)/fs))/pi;
[b,a]=butter(4,fc,'low');
for i=1:n
fil{i}=filtfilt(b,a,data{i});
end
for i=1:n
fil{i}(:,1)=data{i}(:,1);
[p(i),q(i)]=size(fil{i});
end
for j=1:n
for i=10:p(j)-9
if fil{j}(i,4)>=10 & fil{j}(i-9:i-1,4)<10 & fil{j}(i+1:i+9,4)>fil{j}(i,4)
f1(j)=i;
end
if fil{j}(i,4)<=10 & fil{j}(i-9:i-1,4)>10 & fil{j}(i-9:i-1,4)>=fil{j}(i,4)
ff(j)=i-1;
end
end
end
for i=1:n
force{i}=fil{i}(f1(i)+1:ff(i),:);
end
% for i=1:n
% xlswrite('data.xlsx',fil{i},i)
% end
2 Commenti
madhan ravi
il 6 Gen 2019
please select the code and press the code button so that it’s easy to read
dpb
il 6 Gen 2019
Madhan's request is important but even more than that, attach the error message in context ...
Risposte (1)
Jan
il 7 Gen 2019
Modificato: Jan
il 7 Gen 2019
I guess, that the path is missing when you open the files:
listf = dir('E:\New folder (5)\data\*.txt');
n = length(listf);
for k = 1:n
% File WITH full path:
filename = fullfile(listf(k).folder, listf(k).name);
data{k} = textread(filename);
end
Without the full path, Matlab searchs in the current directory, but you obtauined the files in a specific folder explicitly in the dir() command.
Note: Do you see, how nice formatted code is? If you post the complete error message, there wouldn't be a need to guess what the problem is.
[EDITED] In Matlab versions before R2016b dir does not reply the field folder. Then:
folder = 'E:\New folder (5)\data\';
listf = dir(fullfile(folder, '*.txt'));
...
filename = fullfile(folder, listf(k).name);
2 Commenti
Walter Roberson
il 7 Gen 2019
note: older MATLAB do not record the folder information for dir(). At the moment I do not recall the first release that added it .
Vedere anche
Categorie
Scopri di più su File Operations 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!