Using datetime in surf plot
7 ビュー (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
採用された回答
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
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
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 Center および File Exchange で Data Distribution Plots についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!