Effacer les filtres
Effacer les filtres

Change the format of an output figure of 'findchangepts'-function into datetime format.

2 vues (au cours des 30 derniers jours)
When I use a function such as
it automatically produces a figure. Unfortunately, the x-axis just shows sample numbers as it is not possible to, for example, use a timetable as input...
But I want the figure in datetime format. Right now, it is very inconvenient to change the figure into a dateformat:
[BPTipt, BPTresidual] = findchangepts(data.val) % my data gives me 2 change points
h = get(gca, 'Children');
%% define datenums for Children's xdata:
t = datenum(data.Time(BPTipt));
t1 = [t(1) t(1) NaN t(2) t(2) NaN]; % get the format to set children xData
t2 = [datenum(data.Time(1)) t(1) NaN t(1) t(2) NaN t(2) datenum(data.Time(end)) NaN]; % get the format to set children xData
%% set new datenums as xdata for Children:
datetick('x','mmm yy','keeplimits','keepticks');
and that way I still don't have datetime format...
My questions:
  • Is there an shorter easier way to get the output figure in a datetime format?
  • If not, how can i change a figure with datenums as x-data to a datetime format?

Réponse acceptée

Seth Furman
Seth Furman le 28 Oct 2020
This same figure can be created with the relevant x data by using the plot, title, and xline commands.
load train
t = timetable(linspace(datetime(2020,1,1),datetime(2020,1,2),length(y))',y);
ipt = findchangepts(t.y,'MaxNumChanges',4,'Statistic','rms');
title(sprintf('Number of changepoints = 4\nTotal log weighted dispersion = -33002.6521'));
xline(t.Time(ipt),'Color',[0.4660 0.6740 0.1880]);

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by