Plotting with dates and timesteps

13 次查看(过去 30 天)
Here is part of my script:
%%Parameters
StartDate = '26-Jun-1992';
EndDate = '26-Jun-2012';
TimePlotSteps = 200;
data = xlsread('StockPricesClean(1).xlsx');
%%split data
dates = datestr(data(:,1) + datenum('30-Dec-1899'));
data(:,1) = datenum(dates);
StartI = find(data(:,1) == datenum(StartDate));
EndI = find(data(:,1) == datenum(EndDate));
Data.Dates.numb = data(StartI:EndI,1);
Data.Dates.str = datestr(Data.Dates.numb(:,1), 'dd/mm/yy');
Data.Closing = data(StartI:EndI,5);
clear data
TradeSignal(1:length(macdvec),1)=0;
% Create x-axis vector
x=1:length(TradeSignal);
% Plots with dates
figure(2)
subplot(311)
plot(x,macdvec,'r',x,nineperma)
set(gca, 'XTick',1:TimePlotSteps:length(x), 'XTickLabel',Data.Dates.str)
xlim([0 x(end)]);
title('Trading signals on MACD')
If I set my Timeplotsteps to anything other than '1' the x-axis only runs up to july 1992. however if i keep timeplotsteps to '1' the x-axis runs up to july 2012 as it is supposed to but the x-axis looks terrible due to the small steps on the x-axis. How can I solve this (I am a beginner in Matlab so simplicity is appreciated!!)
thanks!

采纳的回答

Walter Roberson
Walter Roberson 2012-7-2
编辑:Walter Roberson 2012-7-2
And remember, the number of elements in XTickLabel must be the same as the number of elements in XTick.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Grid Lines, Tick Values, and Labels 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by