MATLAB: Subset the plot for the subset of x range


I have a plot of date time temperature from Jan1 to Dec 31. I want to create a plot of the same data for Jan 1 to Jun 31. Is there any simpler way to do this?

Best Answer

There is a built-in funtion included with the financial toolbox.
1) daysact - It can return the number of days between two dates. If you data contains the same number of elements in the year, you can use this function to know where to stop reading the data, exactly in Jun 31.
% Create index to stop reading data
numDays = daysact('1-jan-2019', '31-jun-2019');
% Create the new vector
newData = data(1:numDays);