Plotting specified date intervals
Afficher commentaires plus anciens
I have two date intervals: from
25-July-2017 from 9:00 AM to 25-July-2017 12:30 PM and from
26-July-2017 from 9:00 AM to 26-July-2017 12:30 PM.
I am not able to remove the duration in between (from 12:30 PM to the next day 9:00 AM).

A = readtable('Time and Sale_7_25_2017.xlsx');
B = readtable('Time and Sale_7_26_2017.xlsx');
A.Date = datetime(A.Date,'ConvertFrom','excel');
B.Date = datetime(B.Date,'ConvertFrom','excel');
figure(1)
plot(A.Date, A.Price,B.Date, B.Price, '-r', 'linewidth', 2);
datetick('x', 'dd-mmm HH:MM:SS','keeplimits','keepticks')
xlabel('Period')
ylabel('Price')
grid on
grid minor;
8 commentaires
Akira Agata
le 31 Juil 2017
Similar question was answered in the following. Though this Q&A is written in Japanese, images and MATLAB scripts will be helpful.
Seems like requires a lot of work -- would think TMW would have developed weekday functions specifically for such purposes already.
ADDENDUM Misread the dates; was thinking it was a Friday/Monday gap hence reference to weekends. Albeit same issue of gap in data is going to happen if use absolute times for the axis.
ayman alzayed
le 31 Juil 2017
dpb
le 31 Juil 2017
Why not? While convoluted, it does generate a plot with the two sections more closely spaced.
What, specifically, do you think required to "fix" the problem?
If you mean to have the two series connected by continuous line, the simplest alternative would be to use the basic idea of the first solution but instead of using two segments to go ahead and concatenate them as
price=[A.Price;B.Price]; % combine price vectors
plot(price); % plot against ordinal number
then set the ticks and tick labels as wanted; but the ticks will be 1:N instead of actual dates.
As presently implemented, there's no way to eliminate a section of an axis; if you set the actual dates as numeric values the limits will have to encompass the full range of real dates and the values will be placed where they belong in absolute magnitude relative to that.
Duration arrays have the same problem, when you compute the difference the two days between the two sets will be maintained. You could have two duration arrays zero-based from the beginning of the two segments, and then shift the second from the end of the first but that essentially is what using the ordinal position does as you would still have to label the tick values with actual dates manually.
It is, agreed, klunky but I couldn't see that even the Financial Toolbox has a good solution prepackaged; their examples simply interpolate for holidays and draw a continuous curve with fake data to make it look continuous instead of actually handling the business days.
ayman alzayed
le 1 Août 2017
dpb
le 1 Août 2017
Plotted as native dates or durations, no; other than by one of the subterfuges shown or similar.
As for the other, the code is shown above -- join the two vectors into one and plot versus the ordinal number. Then, as the second answer in the other thread shows, label the ticks with the dates (or just use text() to write the dates where ticks are).
ayman alzayed
le 2 Août 2017
dpb
le 2 Août 2017
So did the example below provide the desired result?
Réponse acceptée
Plus de réponses (1)
ayman alzayed
le 3 Août 2017
1 vote
Catégories
En savoir plus sur Calendar dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
