# interp2 from 6x6 map to 500x500 map

1 view (last 30 days)
anto on 28 Jan 2023
Commented: anto on 30 Jan 2023
I have this matrix which represents a profile of velocity which my model gave as an output:
V = [55.4710 58.8408 64.2922 64.3100 58.8997 55.4584;...
31.4855 33.5256 39.2656 39.2657 33.5190 31.4851;...
32.2817 38.7198 44.8627 44.8602 38.7216 32.2812;...
32.3167 38.7370 44.8789 44.8765 38.7389 32.3162;...
31.5531 33.4961 39.2318 39.2320 33.4895 31.5529;...
55.7294 59.0097 64.4591 64.4769 59.0688 55.7165];
which physically represents nodal values in a mesh, which visualized is : the coordinates of the vertical and horizontal line forming the mesh are:
N_mesh = 6;
dx = 1*(0:1/N_mesh:1);
dy = 1*(0:1/N_mesh:1);
I want to use the interpolation "interp2" with the "nearest" option, to create a map for example 500x500.
I looked for documentation but can't seem to use the correct things to successfully do what I have in mind.
For example I tried using 'meshgrid', but since the dx has 7 points, and the map has 6 points the image is not centered...
I tried this:
dx = 1*(0:1/(N_mesh-1):1); %defining nodal points
dy = 1*(0:1/(N_mesh-1):1);
[X,Y] = meshgrid(dx,dy);
Xq = linspace(0,1,500); %defining points for the bigger map
Yq = linspace(0,1,500);
[Xq,Yq] = meshgrid(Xq,Yq);
V_500x500 = interp2(X,Y,V,Xq,Yq,"nearest"); %interpolating
figure() %visualizing the result
contourf(V_500x500)
colorbar
title('interp2 output') But the image is not centered at the extremes...
the problem is that the original dx are dx = 1*(0:1/N_mesh:1); , but for using meshgrid I have to use dx = 1*(0:1/(N_mesh-1):1);
I just wanted the first image I attached being in the bigger map.
Does anybody know how to get the centered image with interp2?
Any help would be greatly appreciated.

Jan on 28 Jan 2023
Of course, 1*(0:1/N_mesh:1) has N_mesh+1 points.
"But the image is not centered at the extremes..." - What does this mean?
By the way, you can omit meshgrid and work with index vectors directly:
V = [55.4710 58.8408 64.2922 64.3100 58.8997 55.4584;...
31.4855 33.5256 39.2656 39.2657 33.5190 31.4851;...
32.2817 38.7198 44.8627 44.8602 38.7216 32.2812;...
32.3167 38.7370 44.8789 44.8765 38.7389 32.3162;...
31.5531 33.4961 39.2318 39.2320 33.4895 31.5529;...
55.7294 59.0097 64.4591 64.4769 59.0688 55.7165];
vx = 1:6;
wx = linspace(1, 7, 501);
wx = floor(wx(1:end-1));
W = interp2(vx, vx.', V, wx, wx.');
figure;
vy = linspace(0, 1, numel(vx));
imagesc(vy, vy.', V); figure;
wy = linspace(0, 1, numel(wx));
imagesc(wy, wy, W); anto on 30 Jan 2023
OK, yes I needed the matrix which you called W, a "centered" (in the sense of properly rescale the 6x6 map) 500x500 matrix in which I can use it for further analysys. Thanks a lot

### Categories

Find more on Interpolation in Help Center and File Exchange

R2022b

### Community Treasure Hunt

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

Start Hunting!