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 Center および File ExchangeFile Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by