Info

This question is closed. Reopen it to edit or answer.

Help I get Error using interp1

1 view (last 30 days)
hmtrondheim Tróndhiem
hmtrondheim Tróndhiem on 5 Jun 2014
Closed: MATLAB Answer Bot on 20 Aug 2021
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

Answers (0)

Community Treasure Hunt

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

Start Hunting!