Verfasst am: 11.09.2015, 14:05
Titel: Interpolation creates NaN
Hei, I'm trying to interpolate over NaN in Matlab.
I have two instruments. Both are measuring in different time. The first (lets call it A) measures every 4 sec. The second one (call it B) measures every 30 sec. A is supposed to be my main instrument. Everything should be in the same time and height grinding as A.
Code:
% time formatting
A.dt = round(nanmedian(diff(A.time_midnight)));
A.base_time = A.base_time/(3600*24)+datenum('01-Jan-197000:00:00');
A.true_time = A.time_offset./(3600*24)+A.base_time*ones(length(A.time_offset),1); % convert so using datevec on all file times is possible
A.tvec = datevec(A.true_time); % 6-col. time vector: [YYYY MM DD HH MM SS] (one line per timestep)
A.time_decimal = A.tvec(:,4) + A.tvec(:,5)./60 + A.tvec(:,6)./3600; % convert times from Julian Day to decimal hour of the day
I do the same for instrument B.
To interpolate now the time and the height I use the following interpolation method
Code:
B.bscatt_interp_profiles=zeros(length(B.height),length(A.time_decimal)) for i=1:length(B.height)
B.bscatt_interp_profiles(i,:)=interp1(B.time_decimal,B.bscatt(i,:),A.time_decimal);
end
B.bscatt_interp=zeros(length(A.height),length(A.time_decimal)) for i=1:length(B.time_decimal)
B.bscatt_interp(:,i)=interp1(B.height,B.bscatt_interp_profiles(:,i),A.height);
end
interp1 is only for interpolation not for extraplolation. if your a.timedecimal ist not in the bounds of B.time_decimal it produces nans. that would be my guess without running code that produces the error
_________________
B.bscatt_interp_profiles=zeros(length(B.height),length(A.time_decimal)) for i=1:length(B.height)
B.bscatt_interp_profiles(i,:)=interp1(B.time_decimal,B.bscatt(i,:),A.time_decimal,'linear','extrap');
end
B.bscatt_interp=zeros(length(A.height),length(A.time_decimal)) for i=1:length(B.time_decimal)
B.bscatt_interp(:,i)=interp1(B.height,B.bscatt_interp_profiles(:,i),A.height,'linear','extrap');
end
vq = interp1(x,v,xq,method,extrapolation) specifies a strategy for evaluating points that lie outside the domain of x. Set extrapolation to the string, 'extrap', when you want to use the method algorithm for extrapolation. Alternatively, you can specify a scalar value, in whichcase, interp1 returns that value forall points outside the domain of x.
Du kannst Beiträge in dieses Forum schreiben. Du kannst auf Beiträge in diesem Forum antworten. Du kannst deine Beiträge in diesem Forum nicht bearbeiten. Du kannst deine Beiträge in diesem Forum nicht löschen. Du kannst an Umfragen in diesem Forum nicht mitmachen. Du kannst Dateien in diesem Forum posten Du kannst Dateien in diesem Forum herunterladen
MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.