How can I show the time on Y axis on Bar graph or Stem graph with datetick ?
    5 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
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 comentarios
Respuestas (1)
  Ian Townend
      
 el 7 de Nov. de 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 comentarios
Ver también
Categorías
				Más información sobre Discrete Data Plots en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

