Plot data from 2 or more timeseries with different x axis scale

1 vue (au cours des 30 derniers jours)
AF le 17 Oct 2022
Modifié(e) : AF le 18 Oct 2022
Hi everyone,
i have to plot 2 or more files as 1x1 timeseries from workspace. This is not the problem. The code looks like this:
plot(simout.x1), hold on, grid on, plot(simout.x2),
xlim([0 31536000]), xlabel('time]'),ylabel('xxxx'),
hold off
Because I simulate a year and have the data in seconds, I would like to have the X axis as months (Jan, Feb, Mar,...) in the plot of the whole year. Sometimes I would like to show only sections where the data in hours or days would be helpful.
Is there a way to implement this easily?
I have already tried some commands but could not do it. Would be glad about tips. Greetings

Réponse acceptée

Jiri Hajek
Jiri Hajek le 17 Oct 2022
If you supply to the plot command also x data - datetime class, then the plot will have the expected look by efault, and it will dynamically change the displayed units based on zoom.
  5 commentaires
AF le 18 Oct 2022
Modifié(e) : AF le 18 Oct 2022
Very good. Thank you.
It works like this. I just had to add ".Data" to simout.x1. I then inserted the second plot with "hold on" and the same timeVector. Like this:
d = '2020-01-01 01:03:08.012';
t = datetime(d,'InputFormat','yyyy-MM-dd HH:mm:ss.SSS');
timeVector = t+seconds(simout.x1.Time);
plot(timeVector, simout.x1.Data), hold on, plot(timeVector, simout.x2.Data)
Thank you very much.

Connectez-vous pour commenter.

Plus de réponses (0)


En savoir plus sur Time Series Events dans Help Center et File Exchange




Community Treasure Hunt

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

Start Hunting!

Translated by