How to interpolate and plot discrete measurement data corresponding to spacial coordinates?

19 views (last 30 days)
Hi,
I have discrete temperature data (55x1 double) related to spacial coordinates (x,y,z all 55x1 double).
It should show the temperature distribution of a human scalp.
So far i could realize a simple scatter3 plot, where you can see the different temperatures (by color) at their measurement position.
Is it possible to interpolate the temperature from one measurement point to the neighbour points and plot a surface, that depicts the surface of the head (approx.) colored regarding its temperature?
Attached you can find the scatter3 plot and a sample dataset.
Code (scatter3):
load('coordinates_and_temperature.mat');
scatter3(x,y,z,100,T(1:55,1), 'filled');
colorbar;
I allready tried to build something with scatteredInterpolant, but unfortunately I am not able to plot the results.
Code (scatteredInterpolant):
load('coordinates_and_temperature.mat');
[X,Y,Z]=meshgrid(x,y,z);
F=(scatteredInterpolant(x,y,z,T));
V=F(X,Y,Z);
Honestly, I don't know what ist happening in the section above. I think V should be the interpolatet temperature data in x,y,z ?!
If so, how could I plot the interpolatet data only on the approximated surface?
I hope you can help me. If you need any more information don't hesitate to ask.
Kind regards,
Philip

Accepted Answer

Star Strider
Star Strider on 8 Oct 2022
It is definitely possible to interpolate those values to a finer set of coordinates and to use scatter3 to display them with respect to temperature.
Try something like this —
LD = load(websave('coordinates_and_temperature','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1149095/coordinates_and_temperature.mat'))
LD = struct with fields:
T: [55×1 double] x: [55×1 double] y: [55×1 double] z: [55×1 double]
x = LD.x;
y = LD.y;
z = LD.z;
T = LD.T;
N = 500;
xv = linspace(min(x), max(x), N);
yv = linspace(min(y), max(y), N);
[Xm,Ym] = ndgrid(xv, yv);
Zm = griddata(x,y,z,Xm,Ym);
Tm = griddata(x,y,T,Xm,Ym);
figure
scatter3(Xm(:),Ym(:),Zm(:), 10, Tm(:))
colormap(turbo(N))
grid on
hcb = colorbar;
tix = hcb.Ticks;
hcb.TickLabels = compose('%5.1f°C',tix);
hcb.Label.String = 'Temperature';
xlabel('X')
ylabel('Y')
zlabel('Z')
This uses two separate griddata calls, one to interplate the surface values and another to interpolate the temperatures, and adds the colorbar. .
.
  12 Comments
PG
PG on 9 May 2023
I apologize for the delay in my response.
I still have concerns about your approach, specifically with regards to the interpolation of T over only x and y, despite its dependence on x, y, and z. While the resulting interpolation may appear visually satisfying due to its completeness, it may lead to an incorrect distribution. In reality, this problem seems to be more of a 4D case rather than a 3D one.
Once again, I appreciate your effort, and unless you have any further advice or ideas, I think we can conclude our discussion.
Best regards
Star Strider
Star Strider on 9 May 2023
As always, my pleasure!
No worries on the delay.
Part of the problem is that I likely do not completely understand what you want to do, or the constraints of the depiction of the data, especially ‘Tm’, since one of the matrices used to create it is ‘Zm’ and ‘Zm’ is itself interpolated. That information may be difficult to describe, however it appears to me that using an interpolated matrix as an interpolant may cause the artefacts in the resulting image, those artefacts being the problem. I am not certain that there is a solution to that.
Creating ‘Tm’ without using ‘Zm’ produces an artefact-free result, however that apparently is not the desired result for reasons that I do not understand. I doubt that creating an artefact-free result that meets your other requirements is possible. I wish that it was.

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!