3D Oceanic Temperature Interpolations in MATLAB

669 Views Asked by At

I am running autonomous underwater vehicle missions which give me lat, long, depth, and temperature data that I am trying to create 3D interpolations with. I am able to create the 3D model of the environment but I am trying to have the color fill be the interpolated temperature at each associated position.

The image below is the 3d depth chart I get that I want to have the fill color be the temperatures at those locations:

I have tried using colormap where surf(X, Y, Z, C) and C is the temperature data but that does not work.

This is what I have for code where VPSA is my data set and X = longitude, y = latitude, Z = depth, and C = temperature

%Making Variables:
X = VPSA {:,1};
Y = VPSA {:,2};
Z = VPSA {:,3};
C = VPSA {:,4};

%Three axis plot
%Plotting Variable with coordinates
xi = linspace(min(X),max(X),1000);
yi = linspace(min(Y),max(Y),1000);

[Xi,Yi] = meshgrid(xi,yi);
Zi = griddata(X,Y,Z, Xi,Yi);
mesh (Xi,Yi,-Zi)
    xlabel('Latitude')
    ylabel('Longitude')
    zlabel('Depth') 

UPDATE: I added the following lines of code

Ci = griddata(X,Y,C,Xi,Yi);
mesh(Xi,Yi,-Zi,Ci)
 

to get the following figure, but it is so hard to tell what is going on, I wonder if there is a way to smooth the interpolation out into a box so it isn't as jagged. enter image description here

Thank you!!

2

There are 2 best solutions below

4
mimocha On BEST ANSWER

I am assuming that the original X,Y,Z,C data points are matched, and you can use the command mesh(X,Y,Z,C) to get a usable plot. Now you are looking to do the same, but with an interpolated dataset.

In this case, you only need to give the mesh command a the color data C.

C also needs to be interpolated, so maybe something like:

Ci = griddata(X,Y,C,Xi,Yi); % Interpolate C the same way you did for Z
mesh(Xi,Yi,-Zi,Ci)

Edit: Apologies for the previous incorrect answer.

0
Tasos Papastylianou On

It's hard to know exactly what you mean by "does not work" or what the nature of your temperature matrix C is, but the specification for C is as follows:

  • same size as Z (more specifically, each element in Z corresponds to each element of C in the same position)
  • each element in C is an integer, corresponding to a position in the current colormap. (which means if you update your colormap, your surface plot will update accordingly)
  • The integers can be inspected / changed after plotting, via the cdata property of your surface plot.
  • You may have to change whether your plot treats your colormap as scaled or direct (i.e. the cdatamapping). Have a look at your object's properties to find out.