![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/318727/image.jpeg)
Creating a mesh plot with data in a timetable
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi there,
Assume that I create a time table based on a matrix as follows.
X = rand(5,3);
Time = seconds(1:5);
TT = array2timetable(X,'RowTimes',Time)
Now I want to get a meshz plot with x axis to be the Time vector and and showing dateticks as xtick labels.
I tried
meshz(TT{:,:})
but this will show xticks NOT as dateticks as in Time ?
Can anyone please help me with this ?
Thank you.
0 commentaires
Réponse acceptée
dpb
le 18 Juin 2020
OK, the above conversation branched another route --
time=datenum(Time); % convert to datenum since they're doubles underneath...
meshz(time,Y,Z)
xt=xticks; xticks(xt(1:3:end)) % not going to be room for very many tick labels so cut 'em down...
datetick('x','mmmyy HHAM','keepticks','keeplimits')
results in![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/318727/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/318727/image.jpeg)
2 commentaires
dpb
le 19 Juin 2020
Yeah, in general datenum has been superseded by datetime but there are still some functions that haven't been updated to be aware of the new class...for those, datenum still has some value despite the general advantages otherwise.
Possibly worth an enhancement request to put on the longer-term wish list but one sorta' doubts there's too much demand for meshz with a time axis...but at least one! :)
Plus de réponses (1)
dpb
le 18 Juin 2020
Modifié(e) : dpb
le 18 Juin 2020
That form for meshz doesn't use any x-,y-coordinates at all -- it just plots against the ordinal position numbers of the Z arrays -- documentation says from 1:N and 1:M but observation shows the above uses 0:N-1 and 0:M-1 instead.
But, even using the meshz(X,Y,Z) syntax that would be required to put an explicit axis on the plot doesn't solve the problem as meshz isn't enhanced to accept a time or duration class input -- when you try,
>> Y=1:3; % a Y coordinate to go along with Time
>> Z=rand(numel(Y),numel(Time)); % a 2D array that matches X, Y
>> meshz(Time,Y,Z) % and goes boom!
Error using meshz (line 56)
Input arguments must be numeric or objects which can be converted to double.
>>
For something simple that you've shown here, the fix would be to just label the axis...
meshz(seconds(Time),Y,Z) % plot a meshz of the Time vector values
hAx.XAxis.TickLabels=compose('%d sec',Time); % label the x-axis as time/duration
xlabel('T'); ylabel('Y'); zlabel('Z') % label the axes
produces![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/318621/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/318621/image.jpeg)
4 commentaires
dpb
le 21 Juin 2020
I showed the datenum/datetick route above...it will work. Show code/problem/error.
NB: It is datetick singular, not dateticks
Voir également
Catégories
En savoir plus sur Dates and Time dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!