MATLAB: Plotting one curve with two colors colourscurveplot Hello friends, I want to plot my curve from 15.01.2018 until 14.10.2018 with a bright green and from 15.10.2018 until 15.07.2019 with a dark green. Can someone explain to me how can I do this? Thank you in advance 🙂 Best Answer Try this: dnv = datenum({'15.01.2018','14.10.2018','15.10.2018','15.07.2019'}, 'dd.mm.yyyy'); % Limitsdn = dnv(1):dnv(end); % Continuous Dates Vectors = sin(linspace(0, 2*pi, numel(dn))); % Create Dependent Variable Datadnd{1} = (dn >= dnv(1)) & (dn <= dnv(2)); % Light Green Limitsdnd{2} = (dn >= dnv(3)) & (dn <= dnv(4)); % Dark Green Limitsfigureplot(dn(dnd{1}), s(dnd{1}), 'Color',[0.1 0.8 0.1], 'LineWidth',2)hold onplot(dn(dnd{2}), s(dnd{2}), 'Color',[0.1 0.5 0.1], 'LineWidth',2)hold offgriddatetick('x', 'dd.mm.yyyy', 'keepticks')set(gca, 'XTickLAbelRotation', 30)Experiment to get the result you want. Related SolutionsMATLAB: Convert excel date to datetime The format has to match exactly. Both of these work: S.textdata = '20-Nov-18 12:00:00 PM GMT';d1 = datetime(S.textdata(1:end-4), 'InputFormat', 'dd-MM-yy hh:mm:ss a', 'TimeZone', 'UTC')d2 = datetime(S.textdata, 'InputFormat', 'dd-MM-yy hh:mm:ss a ''GMT''', 'TimeZone', 'UTC')producing: d1 = datetime 20-Nov-2018 12:00:00d2 = datetime 20-Nov-2018 12:00:00Experiment to get the result you want. MATLAB: How to create timeline plot Try this: North = [datenum([2019 01 30]), datenum([2019 04 12]); datenum(2019,07,03) datenum(2019,08,25)];Central = [datenum(2019,01,08) datenum(2019,03,03)];figureplot(North', ones(2)*2, '-b', 'LineWidth', 5);hold onplot(Central, [1 1], '-r', 'LineWidth',5)hold offylim([0 3])datetick('x', 'mmm')set(gca, 'YTick',[1 2], 'YTickLabel',{'Central','North'})There are also other options, for example using the patch function. It depends on what you want to do. Related QuestionCreating four arrays from two cell arraysPlotting dates on x-axisPlot vector where negative data is circledHow to create a timelinePlot Solid Positive-Valued/Dashed Negative-Valued Contour Plot
Best Answer