Duration of time values for separate datasets and plotting on x-axis
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have the following data sets that have in the x-axis time in "HH:mm:ss". Each data set has different numbers of "times" but they are all within a 2hr duration.
I want to plot this data in terms of duration on the same axes.
Sorry this is the update data.
set0_time=["085440","091530","092000","093020","100000","100020","101325"];
set0_ydata=[30 50 60 72 82 85 88];
H_set0 = str2double(extractBefore(set0_time(:),3));
M_set0 = str2double(extractBetween(set0_time(:),3,4));
S_set0 = str2double(extractAfter(set0_time(:),4));
D_set0 = duration(H_set0,M_set0,S_set0);
t_minutes_set0 = minutes(D_set0);
set1_time = ["121101","121105","130001","133025","140000"];
set1_ydata=[40 50 60 70 89];
H_set1 = str2double(extractBefore(set1_time(:),3));
M_set1 = str2double(extractBetween(set1_time(:),3,4));
S_set1 = str2double(extractAfter(set1_time(:),4));
D_set1 = duration(H_set1,M_set1,S_set1);
t_minutes_set1 = minutes(D_set1);
tdiff_minutes_set1 = t_minutes_set1 - t_minutes_set0(1:5); %There is an issue selecting the first five of set0 as the shift is not accurate
tdiff_shift_set1 = t_minutes_set1-tdiff_minutes_set1;
set2_time = ["103235","110010","120000","130130"];
set2_ydata=[37.8 70 85.7 93.6];
H_set2 = str2double(extractBefore(set2_time(:),3));
M_set2 = str2double(extractBetween(set2_time(:),3,4));
S_set2 = str2double(extractAfter(set2_time(:),4));
D_set2 = duration(H_set2,M_set2,S_set2);
t_minutes_set2 = minutes(D_set2);
tdiff_minutes_set2 = t_minutes_set2 - t_minutes_set0(1:4); %There is an issue selecting the first four of set0 as the shift is not accurate
tdiff_shift_set2 = t_minutes_set2-tdiff_minutes_set2;
figure(15)
scatter(t_minutes_set0,set0_ydata,'Marker','o', 'DisplayName','set0') %updated this line
hold on;
scatter(tdiff_shift_set1,set1_ydata,'Marker','*', 'DisplayName','set1')
scatter(tdiff_shift_set2,set2_ydata,'Marker','+', 'DisplayName','set2')
hold off
xlabel('Duration');
ylabel('Data');
legend
I'm not sure how to get all the data on the same plot but in the same "duration" of time.
Any help is appreciated.
0 Commenti
Risposta accettata
Steven Lord
il 24 Set 2024
set0_time=["085440","091530","092000","093020","100000","100020","101325"];
set0 = set0_time;
set0_ydata=[30 50 60 72 82 85 88];
H_set0 = str2double(extractBefore(set0(:),3));
M_set0 = str2double(extractBetween(set0(:),3,4));
S_set0 = str2double(extractAfter(set0(:),4));
D_set0 = duration(H_set0,M_set0,S_set0);
t_minutes_set0 = minutes(D_set0);
% *snip the other data sets*
figure(1)
% scatter(set0_time,set0_ydata,'Marker','o', 'DisplayName','set0')
You didn't intend to use the string array set0_time in this scatter call, did you? I'll show what that would do after what I believe is the correct code.
scatter(D_set0, set0_ydata, 'Marker', 'o', 'DisplayName', 'set0') % Changed first input
figure
scatter(set0_time,set0_ydata,'Marker','o', 'DisplayName','set0') % won't work
5 Commenti
Steven Lord
il 24 Set 2024
Okay, so do you mean you want each of set0, set1, and set2 to start at 0? In that case don't combine the data sets. Just subtract the first element of each set from the rest of that same set.
set0_time=["085440","091530","092000","093020","100000","100020","101325"];
d0 = convert(set0_time)
d0_start = d0 - d0(1)
Note that the first element is 0.
d0_minutesElapsed = minutes(d0_start)
Do the same for the second set.
set1_time = ["121101","121105","130001","133025","140000"];
d1 = convert(set1_time)
d1_start = d1 - d1(1)
d1_minutesElapsed = minutes(d1_start)
And the third.
set2_time = ["103235","110010","120000","130130"];
d2 = convert(set2_time)
d2_start = d2 - d2(1)
d2_minutesElapsed = minutes(d2_start)
Or were you looking more for the difference between corresponding elements of the same set?
d0 % Reminder of the values from d0
d0_spacing = [0, diff(d0)]
By this, the second element of d0 is just under 21 minutes after the first element and the third element is 4 and a half minutes after the second. I added the 0 at the start because the output of diff for many types is one element shorter than the input and the first element of d0 is 0 minutes after the first element.
function dt = convert(t)
hms = double(t);
s = mod(hms, 100); % least significant two digits
hm = (hms-s)/100; % hm is an integer after the division
m = mod(hm, 100); % middle two significant digits of hms
h = (hm-m)/100; % again, by the way m was constructed h is an integer after division
dt = duration(h, m, s);
end
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Dates and Time in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!