help with interp2 and interpolation

1 visualización (últimos 30 días)
Barry H
Barry H el 16 de Mayo de 2012
Hi,
I'm working to write a script which takes a particle's position in the ocean and interpolates its location and the coastline to find the minimum distance to the closest point on coastline.
In debug mode, I find:
size(y_float_init) = 1 189960
size(x_float_init) = 1 189960
size(dist(j,i)) = 1 1
size(dist(:,:) = 541 546
My guess is that I need to reshpae a variable or two, but I'm not sure. Any suggestions/comments are greatly appreciated
It returns the following errors
Error using griddedInterpolant Interpolation requires at least two sample points in each dimension.
Error in interp2/makegriddedinterp (line 220) F = griddedInterpolant(varargin{:});
Error in interp2 (line 125) F = makegriddedinterp({X, Y}, V, method);
Error in float_distance_coast (line 70) dist_offshore_init(j,i) = interp2(X,Y,dist,X1,Y1);
Thanks for the help!
______________________
[m n]=size(x_rho);
for i = 1:n
for j = 1:m
x_o = x_rho(j,i);
y_o = y_rho(j,i);
for ii = 1:n
for jj = 1:m
x_1 = x_rho(jj,ii);
y_1 = y_rho(jj,ii);
dist_1(jj,ii) = sqrt(((x_o-x_1)^2)+((y_o-y_1)^2));
end
end
ind = find(mask_rho==0);
dist(j,i) = min(dist_1(ind));
end
end
x_float = nc_varget(fname, 'x'); %load in trajectories
y_float = nc_varget(fname, 'y'); %Using metric units
%initial position
x_float_init = x_float(49,:);
y_float_init = y_float(49,:);
for i = 1:size(x_float_init)
X = 1:(size(x_float_init));
Y = 1:(size(y_float_init));
[X,Y] = meshgrid(Y,X);
X1 = 1:(size(x_rho));
Y1 = 1:(size(y_rho));
[X1,Y1]= meshgrid(Y1,X1);
%keyboard
dist_offshore_init(j,i) = interp2(X,Y,dist,X1,Y1);
end

Respuestas (1)

Patrick
Patrick el 17 de Mayo de 2012
What are your m and n ?
And I would use ndgrid and interpn. They don't tranpose like interp2/interp3 and meshgrid, so its alot less confusing.

Categorías

Más información sobre Statistics and Machine Learning Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by