How to solve 'SamplePoints' value contains Inf or NaT. ?

조회 수: 1 (최근 30일)
hanif hamden
hanif hamden 2020년 3월 5일
댓글: hanif hamden 2020년 3월 6일
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
darova
darova 2020년 3월 5일
You can remove NaN or inf
ix = isnan(data*0); % indices of NaN values

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

채택된 답변

Steven Lord
Steven Lord 2020년 3월 5일
A relevant section of your code:
dtm = datetime(dt,'InputFormat','yyyyMMddHHmmss.SS');
% end
% end
M{i} = movmean(y,k,'SamplePoints',dtm);
My guess is that some of the entries in dt don't match the InputFormat you specified and so the corresponding elements of dtm are NaT. Here's a smaller example that demonstrates what I mean.
>> q = datetime({'2020-03-05'; '2020'}, 'InputFormat', 'yyyy')
q =
2×1 datetime array
NaT
01-Jan-2020
'2020-03-05' doesn't match the format 'yyyy'. Use isnat to locate the NaT elements in dtm and check the corresponding entries in dt. If they all have a second format convert them using that second format and use logical indexing with the output of isnat to replace the NaT values in dtm.
  댓글 수: 1
hanif hamden
hanif hamden 2020년 3월 6일
The problem solved. Thank you Sir for the idea! :)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Array Geometries and Analysis에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by