plot x axis with date string from cell array

2 ビュー (過去 30 日間)
Joyce Shin
Joyce Shin 2017 年 2 月 6 日
コメント済み: Walter Roberson 2017 年 2 月 6 日
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 Center および File ExchangeLabels and Annotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by