Using datetime in surf plot

조회 수: 6 (최근 30일)
stuckinthemuck
stuckinthemuck 2015년 1월 30일
댓글: Star Strider 2025년 4월 25일
I have a bunch of subplots that are linked with linkaxes and I currently use the FEX function dynamicDateTicks to update the tick labels when I zoom. BUT. The new datetime format looks better (less crowded) on the graphs. Only I can't get it (datetime) to work with a surf plot.
Here's a minimal working example:
X = 25:25:100;
T = datenum(2015,01,01,1:4,0,0);
Z = [ 1 2 3 4;
5 6 7 8;
9 10 11 12;
13 14 15 16];
[Xmesh,Tmesh] = meshgrid(X,T);
% Tmesh = datetime(Tmesh,'ConvertFrom','datenum');
figure;
surf(Tmesh,Xmesh,Z);
If you uncomment the one line, this gives me the error:
Error using surf (line 57)
X, Y, Z, and C cannot be complex.
Anyone else have this problem? It seems like a bug, since it works fine with any other plot. For example:
plot(datetime(2014,01,1:2),1:2)
Any help would be appreciated. And just to be clear, I currently can get it all to work with dynamicDateTicks (datetick), I'm just hoping for a cleaner plot.

채택된 답변

Star Strider
Star Strider 2015년 1월 30일
I can’t find it in the documentation just now, but datetime doesn’t work with ‘surface’ plots. It works with 2D plots only.
I believe datetick will still work on ‘surface’ plots.
  댓글 수: 4
Guilherme de Melo
Guilherme de Melo 2025년 4월 25일
Hello Star Strider. My MATLAB 2020 continue not work the datetick with surf command. Do you have some update about how to plot the time with surf? I was trying from my following question: https://www.mathworks.com/matlabcentral/answers/2176629-how-to-improve-spectrogram-plot Thanks in advance.
Star Strider
Star Strider 2025년 4월 25일
@Guilherme de Melo — Use datetime not datetick. I don't remember if it was possible to use datetime arrays in surf plots in R2020a or R2020b, and I no longer have access to that release. I believe datetime works with surf plots currently.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by