variable Xtick on bar graph

hello everyone,
i have this problem: i want to plot on bar figure infomation and wirth below this data the date of any column on the bar. the problem is that the user can choose differnt length of time to see one the graph and its causing to problam (many dates on the Xtick wirte one on the other and think like that). i tried to set that if the user choose more than 8 days so the Xtick will write only 8 days but with proportion between them (for exemple if he choose 16 day so it shoe the dates with jump of 2 days between a couple) but i having trouble to get the right string fo the Xtick. anyone can help? you can see what i done so far to maybe understand better my problem. thanks!
Labels = cellstr(Dates);
NumOfDates = length(Labels);
if NumOfDates < 7
set(gca,'XTick', 1 : NumOfDates, 'XTickLabel', Labels);
else
Labels(1) = Dates(1);
Labels(8) = Dates(end);
j = 2;
for i = 1 + round(NumOfDates/8) : round(NumOfDates/8) : NumOfDates
Labels(j) = Dates(i);
j = j + 1;
end
if strcmp(Labels(end), Labels(end - 1))
Labels(end - 1) = Dates(round(length(Dates) - (NumOfDates/8)));
end
set(gca,'XTick', 1 : (NumOfDates/8): NumOfDates, 'XTickLabel', Labels);
end
labels is the dates string to Xtick. * "Dates" its all the dates of the dtat and from this variable i need to peek max 8 dates.

Respuestas (1)

Walter Roberson
Walter Roberson el 10 de Abr. de 2016

0 votos

I suggest you use linspace(1, NumOfDates, 8), possibly rounding the results.

3 comentarios

nadav potasman
nadav potasman el 10 de Abr. de 2016
Hi Walter, thanks for your answer but i think it will give me a vector of numbers while i need dates accordind to the dates on the variable "Dates".
Walter Roberson
Walter Roberson el 10 de Abr. de 2016
Index the Dates at the rounded index.
Or, if the dates are equally spaced and there are no holes, then you can linspace() the numeric equivalents of the dates.
nadav potasman
nadav potasman el 15 de Abr. de 2016
Thank you again Walter. Im not sure that i understood your idea but meanwhile i succssed to solve my problem Thanks anyway

Iniciar sesión para comentar.

Categorías

Etiquetas

Preguntada:

el 10 de Abr. de 2016

Comentada:

el 15 de Abr. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by