Interpolating a velocity field between time steps

12 vues (au cours des 30 derniers jours)
Timotej Turk Dermastia
Timotej Turk Dermastia le 29 Fév 2016
Hi! I am a relatively new user of Matlab, working on a project of particle advection in a hydodynamic environment. In order to simulate the advection I have to interpolate current velocities between time steps. I have a field of mean current velocities for each day. I want to split the day into 4 hour intervals, hence I would need to interpolate the velocities at 5 extra time steps. My velocity matrix is named MER.u (92x100x15), where the third dimension represents each day (15 in total). When trying to interpolate I am returned with an error ("The grid vectors do not define a grid of points that match the given values.").
I am struggling to construct a sentence where I would tell Matlab to treat MER.u(:,:,it), to be the corresponding value of MER.mt(1). I am aware that a date giving a field of velocities is not exactly a function but I was assuming linear 1D interpolation is the correct method for this (of course I could and likely am wrong). Can you please help with this, it should be fairly easy.
The code I am using is given bellow.
%MER.mt is a vector of 15 dates in datenum format
%MER:u is a grid 92x100x15 of velocities for 15 days
tn= [MER.mt(1):1/6:MER.mt(end)] ;
interp1(MER.mt, MER.u, tn);
  2 commentaires
KSSV
KSSV le 1 Mar 2016
You have a grid of 92X100. There is spatial variation as well as temporal variation. How you can use interp1? Give more information about the problem and data you have.
Timotej Turk Dermastia
Timotej Turk Dermastia le 1 Mar 2016
Modifié(e) : Timotej Turk Dermastia le 1 Mar 2016
Yes I'm aware of this and as I said I don't know whether this is the right approach however My x in interp1(x,v,xq) is a 15x1 vector of times and my xq is a 85x1 vector of new times. My disiried output would be a grid of velocities 92x100x85 where 5 new fields would be calculated between the current time steps.

Connectez-vous pour commenter.

Réponse acceptée

KSSV
KSSV le 1 Mar 2016
u = rand(92,100,15) ; % random xcomponent of veclocity
v = rand(92,100,15) ; % random ycomponent of velocity
t = linspace(1,150,15) ; % time steps
ti = [5,20,70] ; % time where velocities are to be interpolated
% Initialize interpolated components
ui = zeros(92,100,length(ti)) ;
vi = zeros(92,100,length(ti)) ;
for i = 1:92
for j = 1:100
% u comp interpolation
uij = squeeze(u(i,j,:)) ;
ui(i,j,:) = interp1(t,uij,ti) ;
% v comp interpolation
vij = squeeze(v(i,j,:)) ;
vi(i,j,:) = interp1(t,uij,ti) ;
end
end

Plus de réponses (0)

Catégories

En savoir plus sur Interpolation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by