Why textread in MATLAB error?

1 visualización (últimos 30 días)
elham ghalenoii
elham ghalenoii el 6 de En. de 2019
Comentada: Jan el 7 de En. de 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 comentarios
madhan ravi
madhan ravi el 6 de En. de 2019
please select the code and press the code button so that it’s easy to read
dpb
dpb el 6 de En. de 2019
Madhan's request is important but even more than that, attach the error message in context ...

Iniciar sesión para comentar.

Respuestas (1)

Jan
Jan el 7 de En. de 2019
Editada: Jan el 7 de En. de 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 comentarios
Walter Roberson
Walter Roberson el 7 de En. de 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 el 7 de En. de 2019
Thanks Walter. I've added some code for older Matlab versions.

Iniciar sesión para comentar.

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by