Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Help I get Error using interp1

조회 수: 1 (최근 30일)
hmtrondheim Tróndhiem
hmtrondheim Tróndhiem 2014년 6월 5일
마감: MATLAB Answer Bot 2021년 8월 20일
What am I doing wrong here? I get: "The grid vectors are not strictly monotonic increasing" from interp1. Mask is my try to avoid NaN. Time and res(:,1) both go through a year. Time with 1 every hour,and res(:,1) with every ten minutes.
time = datenum('2013,01,01,01,00,00','yyyy,MM,dd,HH,mm,ss'):1/24:datenum(2013,12,31,23,00,00,'yyyy,MM,dd,HH,mm,ss')
function [ output2 , output1 ] = readRoadstationData( filename , time )
% Tab is delimiter
delimiter = '\t';
% %s are columns included, %*s are columns excluded.
formatSpec = '%s%s%*s%*s%*s%*s%*s%*s%*s%*s%*s%s%[^\n\r]';
%Open the text file 'fileNmae' using fopen().
fileID = fopen(filename,'r');
%Read columns from file using textscan.
dataArray = textscan(fileID,formatSpec,'Delimiter',delimiter,'HeaderLines',1,'ReturnOnError',false);
%close the file
fclose(fileID);
%Convert data from strings to numbers.
res = [datenum(dataArray{1},'yyyy-MM-dd HH:mm:ss'),str2double(dataArray{2}),str2double(dataArray{3})];
mask = ~isnan(res(:,2));
res(:,2) = interp1(res(mask,1), res(mask,2), transpose(time),'nearest');
end

답변 (0개)

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by