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 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