How can I show the time on Y axis on Bar graph or Stem graph with datetick ?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello,
I have a 20x1 cell array and on each cell there is a time in 'MM:SS.FFF'.
I use datenum to convert it in serial number. Now I would like to use a bar graph or stem graph with numeric values in X axis and those time values in Y Axis.
I use datetick after the plot to convert the value in time text but on my graph there is just '00:00.000' on the Y-axis and if I try to plot in plot graph it's working (I have my time values on Y axis).
My code is (with 'h' a 20x1 cell with time values in text):
Format = 'MM:SS.FFF';
z=[1 2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21];
h1= datenum(h,Format);
bar(z,h1)
datetick('y',Format)
Do you have a solution for this problem?
Thank you,
Martin
0 Kommentare
Antworten (1)
Ian Townend
am 7 Nov. 2024
I have just been faced with the same problem. My solution was as follows:
%input y_values as datetime
startdate = min(y_values); %smallest datetime
plotvalues = y_values-startdate; %convert to durations
%create bar plot
bar(ax,x,plotvalues) %ax is handle to axes
y_ticks = ax.YTick; %get the plot ticks as durations
dtime = startdate+y_ticks; %convert to datetime
yticklabels(datestr(dtime)) %relabel as date strings
This was sufficient for my purposes.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Discrete Data Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!