Resampling using Interpolation of ode45 Data in Matlab -
i tried use interp1 solve ode problem... want interpolate previous data equation... below codes...
function dxdt = newforced(t,x1,d) dxdt_1 = x1(2); dxdt_2 = -100*x1(2)-250000*x1(1)+(25000*(d^3)); %data should interpolated @ d dxdt = [dxdt_1;dxdt_2]; tspan=[0:0.1:100]; d=x(:,1); %x data sampling previous ode initial_x1=0; initial_dxdt=0; f=interp1(t,d,x); [t,x1]=ode45(@newforced,tspan,[initial_x1 initial_dxdt]); figure plot(t,x,':') figure plot(d,f)
issue: have 2 variables (d , x(:,1)) , want resample 1 match length of other.
codes above not working many error pops up... can please correct me thanks
here's toy example. replace x
, y
d
, x(:,1)
.
% example data x = 0:9; y = 1:0.1:10; % check if y longer if length(x) < length(y) x = interp1( x, linspace( 1, length(x), length(y) ) ); % resample x else y = interp1( y, linspace( 1, length(y), length(x) ) ); % resample y end
so linespace
generate indicies between 1 , length(x) length(y) number of divisions.
essentially interp1
resample variable length of other one. if statement check 1 needs resampling.