Why textread in MATLAB error?

조회 수: 1 (최근 30일)
elham ghalenoii
elham ghalenoii 2019년 1월 6일
댓글: Jan 2019년 1월 7일
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
madhan ravi
madhan ravi 2019년 1월 6일
please select the code and press the code button so that it’s easy to read
dpb
dpb 2019년 1월 6일
Madhan's request is important but even more than that, attach the error message in context ...

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

답변 (1개)

Jan
Jan 2019년 1월 7일
편집: Jan 2019년 1월 7일
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
Walter Roberson
Walter Roberson 2019년 1월 7일
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 2019년 1월 7일
Thanks Walter. I've added some code for older Matlab versions.

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

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by