"clc clear all close all % load Data TimeLabel = importTime('july3.xlsx'); Data =…
- User
"clc clear all close all
% load Data
TimeLabel = importTime('july3.xlsx'); Data = importData('july3.xlsx');
nDays = 110; TimeLabel = TimeLabel(2:nDays); Data = Data(2:nDays);
TimeLabel = datetime(TimeLabel,"InputFormat","yyyyMMdd"); TimeLabel = string(TimeLabel); ts = timeseries(Data,TimeLabel); ts.Name = 'Close'; ts.TimeInfo.Format = 'mmm dd, yyyy';
% Plot both time series figure plot(ts,'LineWidth',2);"
Expand the code to Divide the graph into two parts, draw from zero to 71 with blue color and draw 71 to the end with orange color.
- Assistant
Here's the updated code that divides the graph into two parts and uses different colors for each part:
clc clear all close all
% load Data TimeLabel = importTime('july3.xlsx'); Data = importData('july3.xlsx');
nDays = 110; TimeLabel = TimeLabel(2:nDays); Data = Data(2:nDays);
TimeLabel = datetime(TimeLabel,"InputFormat","yyyyMMdd"); TimeLabel = string(TimeLabel); ts = timeseries(Data,TimeLabel); ts.Name = 'Close'; ts.TimeInfo.Format = 'mmm dd, yyyy';
% Divide the graph into two parts startIndex = 1; endIndex = 71; figure hold on plot(ts.Data(startIndex:endIndex),'b','LineWidth',2); plot(ts.Data(endIndex+1:end),'Color',[1, 0.5, 0],'LineWidth',2); hold off
% Set the axis label and title xlabel('Time','FontSize',14,'FontWeight','bold') ylabel('Price','FontSize',14,'FontWeight','bold') title('Stock Prices','FontSize',16,'FontWeight','bold')
% Set the axis limits xlim([1 length(ts.Data)]) ylim([min(ts.Data) max(ts.Data)])