% this is to do the grid-based central finite difference for the two vectors dimension as u(lon, lat, time) and v(lon,lat,time). the for loops works fine but it is too slow. I need a helpful loop that is faster than me from Matlab community.
Ur = zeros(291,243,1459); [NR, NC]=size(lat); for k = 1: length(t) for i = 2:NR-1 for j = 2:NC-1 Ur(k,i,j)=sqrt((u(i+1,j,k)-2*u(i,j,k)+u(i-1,j,k))./(lon(i)-lon(i-1)^2) ... +(v(i,j+1,k)-2*v(i,j,k)+v(i,j-1,k))./(lat(j)-lat(j-1)^2)); end end end
Best Answer