Why textread in MATLAB error?

1 vue (au cours des 30 derniers jours)
elham ghalenoii
elham ghalenoii le 6 Jan 2019
Commenté : Jan le 7 Jan 2019
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 commentaires
madhan ravi
madhan ravi le 6 Jan 2019
please select the code and press the code button so that it’s easy to read
dpb
dpb le 6 Jan 2019
Madhan's request is important but even more than that, attach the error message in context ...

Connectez-vous pour commenter.

Réponses (1)

Jan
Jan le 7 Jan 2019
Modifié(e) : Jan le 7 Jan 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 commentaires
Walter Roberson
Walter Roberson le 7 Jan 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 .
Jan
Jan le 7 Jan 2019
Thanks Walter. I've added some code for older Matlab versions.

Connectez-vous pour commenter.

Catégories

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

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by