plot x axis with date string from cell array

2 views (last 30 days)
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)));

Answers (1)

Walter Roberson
Walter Roberson on 6 Feb 2017
Try
set(gca, 'XtickLabel', cellstr( datestr(out{1,1}(1:10000:47040)) ) );
  2 Comments
Joyce Shin
Joyce Shin on 6 Feb 2017
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 on 6 Feb 2017
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.

Sign in to comment.

Categories

Find more on Labels and Annotations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!