plot x axis with date string from cell array

2 次查看(过去 30 天)
Hi, I am plotting a graph with x-axis with date string in this format ('12/19/16 0:00', '12/20/16 10:30'). X-axis values are stored in 47040 * 1 cell array, and I picked representative 5 values to put on X-axis. However, it only outputs first value of an array.
Do you see why it is printing this way?
figure;
for k=1:7
diffSum = 0;
for i=(1+(k-1)*size(c,1)):(k*size(c,1))
diff = CumDiff(:,i);
diffSum = diffSum+ diff;
end
legend('-DynamicLegend');
plot(diffSum, 'color', rand(1,3), 'LineWidth', 3, 'DisplayName', sprintf('Group Thermal Comfort: %d', tc(k)));hold on;
legend('show');
drawnow;
end
xtickangle(45);
set(gca,'Xtick',1:10000:47040);
set(gca,'XtickLabel',datestr(out{1,1}(1:10000:47040)));

回答(1 个)

Walter Roberson
Walter Roberson 2017-2-6
Try
set(gca, 'XtickLabel', cellstr( datestr(out{1,1}(1:10000:47040)) ) );
  2 个评论
Joyce Shin
Joyce Shin 2017-2-6
Thank you for the comment. But I still get the one value only. Strangely, if I provide an array with values, it prints all the values to (0,0). How should I fix my code?
set(gca, 'XtickLabel', ['12/19/16 0:00', '12/20/16 10:30', '12/21/16 23:15', '12/23/16 10:00', '12/24/16 22:45'] );
Walter Roberson
Walter Roberson 2017-2-6
set(gca, 'XtickLabel', {'12/19/16 0:00', '12/20/16 10:30', '12/21/16 23:15', '12/23/16 10:00', '12/24/16 22:45'} );
Remember, ['A', 'B'] for char means the same as ['AB'] which is 'AB'
The cellstr() was there to convert the char array produced by datestr() into a cell array of strings.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Labels and Annotations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by