필터 지우기
필터 지우기

variable Xtick on bar graph

조회 수: 2 (최근 30일)
nadav potasman
nadav potasman 2016년 4월 10일
댓글: nadav potasman 2016년 4월 15일
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.

답변 (1개)

Walter Roberson
Walter Roberson 2016년 4월 10일
I suggest you use linspace(1, NumOfDates, 8), possibly rounding the results.
  댓글 수: 3
Walter Roberson
Walter Roberson 2016년 4월 10일
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 2016년 4월 15일
Thank you again Walter. Im not sure that i understood your idea but meanwhile i succssed to solve my problem Thanks anyway

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by