Plotting two curves on a Datetime scale.

2 views (last 30 days)
Data 1
Coloumn 1(Datetime) Coloumn 2 (Temperature)
'2019-07-03T16:06:48' 24
'2019-07-03T16:08:48' 24
'2019-07-03T16:09:48' 25
'2019-07-03T16:10:48' 25
'2019-07-03T16:11:48' 25
'2019-07-03T16:12:48' 25
'2019-07-03T16:13:48' 25
'2019-07-03T16:14:48' 25
'2019-07-03T16:15:48' 25
'2019-07-03T16:16:48' 25
'2019-07-03T16:17:48' 25
'2019-07-03T16:18:48' 25
'2019-07-03T16:19:48' 25
'2019-07-03T16:20:48' 25
'2019-07-03T16:21:48' 25
Data 2
Coloumn 1(Time) Coloumn 2 (Temperature)
0 25
20 24.7714
40 24.5304
60 24.2764
80 24.0096
100 23.7305
120 23.4398
140 23.1384
160 22.8269
180 22.5061
200 22.177
220 21.8401
240 21.4962
260 21.1459
280 20.7899
%% Loading the datas :
load('In_Flight_Data.mat');
% Start and end dates for real-time datas obtained
DateStart = datetime('03/07/2019 17:00:00','InputFormat','dd/MM/uuuu HH:mm:ss');
DateEnd = datetime('04/07/2019 08:00:00','InputFormat','dd/MM/uuuu HH:mm:ss');
% Datas index you want to plot
idToPlot = [17];
% Figure initialisation
figure
hold on
leg = {};
% Loop to plot the datas one by one
for i = 1:numel(idToPlot)
idat = idToPlot(i);
% Find the measurement points that are between the start and en dates
id = find((dataTot(idat).Date > DateStart) & (dataTot(idat).Date < DateEnd));
% Plot the data
plot(dataTot(idat).Date(id),dataTot(idat).Value(id));
% Put some text in the leg array, which will be used as legend
leg{end+1} = dataTot(idat).Name;
end
% Format the graph
legend(leg); % give a ledgend
ylabel('Temperature (°C)'); % Give a label to Y axis
title('Temperatures'); % Give a title
Hello Everyone,
I would like to plot these two datas (Data 1 and Data 2) on the same plot. But one has time in datetime format and one in seconds, how do i do this? I have a code which I have posted above with which I plotted the datetime data (Data1). "idToPlot = [17];" This line simply is the index number given to a particular component for which the Datetime datas have been plotted.
Le version en Français
Bonjour à tous, Je voudrais tracer ces deux données (Data 1 et Data 2) sur le même plot. Mais on a l'heure au format datetime et l'autre en secondes, comment faire? j'ai un code que j'ai posté ci-dessus avec lequel j'ai tracé les données datetime (Data1). "idToPlot = [17];" Cette ligne est simplement le numéro d'index attribué à un composant particulier pour lequel les données Datetime ont été tracées.
  2 Comments
dpb
dpb on 14 Dec 2019
Either add a reference start time to the elapsed times of the second set or subtract the initial time from the datetime value of the first to create a duration.
Amal Rai
Amal Rai on 19 Dec 2019
Edited: Amal Rai on 19 Dec 2019
i deleted the second code that i put to avoid confusion. With that code, i was able to plot two curves but the timescale was in seconds, but i want it in datetime scale, so i got more confused.
"Either add a reference start time to the elapsed times of the second set or subtract the initial time from the datetime value of the first to create a duration."
Can you please tell me where do i need to make the changes that you have suggested above to create a duration in my code?
Is it here:
% Plot the data
plot(dataTot(idat).Date(id),dataTot(idat).Value(id));

Sign in to comment.

Accepted Answer

dpb
dpb on 19 Dec 2019
t1=datetime(t1,'InputFormat','uuuu-MM-dd''T''HH:mm:SS'); % convert first to datetime
t2=seconds(0:20:280).'+t1(1); % second based at beginning of first
plot(t1,T1,t2,T2) % temperatures are T1,T2 from your variables
results in
untitled.jpg
Alternatively, keep t1 as seconds() and
t2=t1-t1(1);
to turn it also into duration from zero.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!