How to solve 'SamplePoints' value contains Inf or NaT. ?
Afficher commentaires plus anciens
Hi everyone.
Can anyone help me to solve this error? The error showing this:
Error using convertMovfunArgs (line 19)
'SamplePoints' value contains Inf or NaT.
Error in datetime/movmean (line 104)
args = convertMovfunArgs(varargin{:});
Error in MAFilt_loop (line 33)
M{i} = movmean(y,k,'SamplePoints',dtm);
I try to do a loop in my script as shown below since I have many files to perform a moving average function. Attached also the example of my input files.I hope that someone can help me solve this matter. Thank you.
*Note: the input files should be kept in MtxjP1 folder and execute the script outside of MtxjP1 folder.
clc;clear all;close all;
p = input('Please enter the pass number:');
for pid=p
%% EDIT FILENAME HERE
path = sprintf('MtxjP%d',pid);
BasePath = 'F:\ERM\Merge_txj\3_Thres_MovAvg\';
newPath = [BasePath path];
txtfiles = dir([newPath '*.txt']);
% Get a list of all files, including folders.
DirList = dir(newPath);
% Get rid of first two folders: dot and dot dot.
DirList = DirList(3:end);
% Sort the files in ascending numbers
[~,ndx] = natsortfiles({DirList.name});
filenames = DirList(ndx);
numfiles = length(filenames);
B=1;
for i= 1:numfiles
%% EDIT FILENAME HERE
formatSpec = sprintf('Mtxjp_FPT%d.txt',i);
A{i} = dlmread(sprintf([path '/' formatSpec],B));
B=B+1;
y = A{i}(:,4);
k = days(90);
dt = num2str(A{i}(:,1),'%.2f');
dtm = datetime(dt,'InputFormat','yyyyMMddHHmmss.SS');
% end
% end
M{i} = movmean(y,k,'SamplePoints',dtm);
Fdata = [A{i}(:,1:3) M{i} A{i}(:,5:7)]
filename = sprintf('Mtxjp_MvPT%d.txt', i);
fid = fopen([path '/' filename],'wt');
%fprintf(fid,'%.12f \t %.6f \t %.6f \t %.3f \t %.0f \t %.0f \t %.4f\n',Fdata.');
fprintf(fid,'%17.2f \t %.6f \t %.6f \t %.3f \t %.0f \t %.0f \t %.4f\n',Fdata.');
fclose(fid);
end
end
1 commentaire
darova
le 5 Mar 2020
You can remove NaN or inf
ix = isnan(data*0); % indices of NaN values
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Text Files dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!