Cubic Spline Interpolation of a 3D surface Plot with Datetick Axis Labels

4 views (last 30 days)
I am attempting to make a 3D surface plot of some numbers that need to have cubic spline interpolation applied to them.
The problem with this is that after doing so I need to label the x axis with a datetick format, not epoch time. Whenever I try to do this, the datetick just defaults to January 1 00:00:00. I was hoping someone could help me with this. An example of my code is below:
simulatedTime = [34630:34929, 34630:34929];
simulatedZ = 350 + 250*rand(600, 1);
simulatedY = [sort(floor(50+10*rand(300, 1))); sort(floor(100+10*rand(300, 1)))];
[xq, yq] = meshgrid(min(simulatedTime):60:max(simulatedTime),...
min(simulatedY):1:max(simulatedY));
zq = griddata(simulatedTime, simulatedY, simulatedZ, xq, yq, 'cubic');
figure;
surf(xq, yq, zq);
xData = datetime(34630:34929, 'convertfrom','posixtime');
datetick('x','HH:MM:SS');
Thank you.

Accepted Answer

Star Strider
Star Strider on 2 Feb 2019
See if this works in your application:
simulatedTime = [34630:34929, 34630:34929];
simulatedZ = 350 + 250*rand(600, 1);
simulatedY = [sort(floor(50+10*rand(300, 1))); sort(floor(100+10*rand(300, 1)))];
[xq, yq] = meshgrid(min(simulatedTime):60:max(simulatedTime),...
min(simulatedY):1:max(simulatedY));
zq = griddata(simulatedTime, simulatedY, simulatedZ, xq, yq, 'cubic');
figure;
surf(xq, yq, zq);
Ax = gca;
xData = cellstr(datetime(34630:34929, 'convertfrom','posixtime'));
Ax.XTickLabel = xData;
It creates a cell array with the cellstr function, then assigns those to the 'XTickLabel' object.
Experiment with it to get the result you want.
  2 Comments
Logan Suarez Parmer
Logan Suarez Parmer on 6 Feb 2019
Edited: Logan Suarez Parmer on 6 Feb 2019
Thank you so much, this was exactly what I was looking for.
Just to check, am I splining the 3D data correctly? Obviously it is random data right now, but if simulatedY was kilometers and simulatedTime was seconds, this would spline and interpolate the Z axis data to the minute/kilometer, right?

Sign in to comment.

More Answers (0)

Categories

Find more on Spline Postprocessing in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!