1

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!!

Emily S
  • 15
  • 5
  • A surface is not a good vehicle to represent a scalar quantity in 3D. A surface could represent the isolevels of your temperature. For the full volume (the 3D domain), you might want to read: [Volume Visualization](https://uk.mathworks.com/help/matlab/volume-visualization.html). – Hoki Jul 24 '20 at 08:36
  • @Hoki Thanks for that suggestion! I think you are correct in that this is not the best way to visualize these data. – Emily S Jul 24 '20 at 17:28

2 Answers2

0

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.

mimocha
  • 1,041
  • 8
  • 18
  • Thank you! Adding the temperature data in the same matrix as Z then meshing it all worked well for me! Do you know if there is a way to smooth out the interpolation so it is not as jagged? I will edit my original post with the updated figure so you see what I mean. Thank you so much! – Emily S Jul 23 '20 at 19:28
  • The function `griddata` offers a few different interpolation methods [docs](https://uk.mathworks.com/help/matlab/ref/griddata.html). The default method being used is linear interpolation, hence the jagged features; the other methods that might give "smoother" results are natural neighbor `griddata(...,'natural')`, and cubic interpolation `griddata(...,'cubic')`. You will have to decide if these will work for your use case. Beyond that, you would have to consider other options, like taking the average of the interpolated dataset, etc. – mimocha Jul 23 '20 at 20:23
  • Is there a way to interpolate to a defined cube? Rather than using a smoothing factor in the griddata function? – Emily S Jul 23 '20 at 21:28
  • Unfortunately I don't know of any MATLAB function that allows you to use custom interpolation methods. Here's the [full documentation page](https://uk.mathworks.com/help/matlab/interpolation.html) for interpolation methods that MathWorks provide. The closest to *what I think you want*, is the function [`mkpp`](https://uk.mathworks.com/help/matlab/ref/mkpp.html), which allows you to create piecewise polynomial functions of arbitrary degree. Although you'll have to figure out how to make an interpolation function from that. – mimocha Jul 24 '20 at 00:19
0

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.
Tasos Papastylianou
  • 21,371
  • 2
  • 28
  • 57