how to limit x axis to specific input

1 view (last 30 days)
kareem
kareem on 3 Jul 2014
Commented: dpb on 3 Jul 2014
so i basically have 4500 data collection from different dates, these data are saved in excel documents and i imported them. i want to plot just specific dates from the whole range. my problem is whenever i plot it doesn't show all data points only about 10 points and it shows all the data.
time_step=([336,00,00]*[3600;60;1])/86400;
start_date=datenum(input('enter start date in dd-mmm-yyyy >> ','s'));
end_date=start_date+time_step;
x=datestr(start_date);
z=datestr(end_date);
a=start_date;
s=end_date;
plot(conv_data(:,1))
set( gca,'xticklabel',[a:s])
  1 Comment
dpb
dpb on 3 Jul 2014
plot(conv_data(:,1))
set( gca,'xticklabel',[a:s])
You don't show how you got conv_data, but you've plotted the first column of whatever it is versus the index 1:length(conv_data). Then, you set the axis ticks to the values of the start and end date but you've done nothing to either--
a) select a subset of the total data within the date ranges, or
b) displayed the data on an x-axis that has any direct time information associated with it.
Hence, it's not surprising your results aren't particularly useful.
You need to convert the time data in the files to Matlab datenums, then plot against that datenum value, then use datetick to convert the axis to a time display. You can then either,
a) set the axis limits (in terms of datenums) to the desired ranges or
b) select the data points within the start/stop datenum ranges desired and plot; this will more-or-less automagically set the axis range for the data as selected. You still need datetick, of course.
NB: also, if the dates are stored as strings/calendar dates in the Excel sheet, it's straightfoward to convert to datenums with datevec and friends; if they're stored as Excel's version of serial dates, then you must make a conversion of reference time. There's a topic in the documentation on doing that.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!