Interpolate x value at single y value in dataset.

Hi,
I have a CSV file with time and temperature values. In the app designer I kind of figured everything out (import file, plot the data, display some data in a table) however I just can’t find a solution for the following problem:
I would like to determine/interpolate the time at which my temperature reaches my threshold of 7°C. The problem is that my temperature is sampled every 15 min so my sampled values bounces above and below my threshold. Here I have the code so far with a code i integrated from a solution to a similar problem I found in Matlab Help (Sorry in advance I am not a good programmer):
% Get the data from the TemperaturDaten table
temperaturTableData = app.Temperaturdaten.Data;
% Get the selected row indices from UserData for Temperaturdaten
temperaturIndices = app.Temperaturdaten.UserData;
% Get selected data on the new figure for Temperaturdaten
for i = 1:length(temperaturIndices)
% Get the data from the selected row
rowData = temperaturTableData(temperaturIndices(i), :);
% Read the CSV file from the selected entry
filename = rowData{1};
fullFilePath = fullfile(pwd, filename);
% Read the CSV file
csvTable = readtable(fullFilePath);
% Convert the table to a timetable to combine Date and
% time of day to a single column
tt = table2timetable(csvTable, 'RowTimes', datetime(csvTable.Datum + csvTable.Zeit,'Format','dd/MM/yyyy HH:mm:ss'));
%convert timetable back to table TT.Wert being the Temperature value
%and TT.Time being the date and time values
TT = timetable2table(tt);
%Get all values above 7°C threshhold
TT.ubersieben = TT.Wert;
TT.ubersieben(TT.ubersieben<7)=0;
%Get time at 7°C threshhold. "This is my problem I can't solve."
dy=diff([0 TT.Wert]);
dyix=find(dy==0);
TT.Wert(dyix)=TT.Wert(dyix-1)+1E-8;
schnittsieben = interp1(TT.Wert,TT.Time,7,"linear");
disp(schnittsieben);
%Export to app design table.
Tabellenausgabe = table(TT.Time, TT.Wert,TT.ubersieben);
end
% Assign data to the UITable
app.UITable.Data = Tabellenausgabe;
The error I get is: “Dimensions of arrays being concatenated are not consistent.
I added a plot to potentially clarify the time values I am looking for.
If someone could point me in the right direction, I would be very thankful.

 Réponse acceptée

Star Strider
Star Strider le 12 Fév 2024
Modifié(e) : Star Strider le 12 Fév 2024
Having your data definitely helps!
Try this —
% DT = datetime(2024,2,12) + minutes(0:15:13*60).';
% TC = rand(size(DT))*6+3;
T1 = readtable('311FT01Temp.csv')
T1 = 384×6 table
Datum Zeit Objektname Parameter Wert Einheit ___________ ________ ______________________________________ ______________ ____ ________ 07-Jan-2024 00:00:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 9.6 {'GRDC'} 07-Jan-2024 00:15:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 13.1 {'GRDC'} 07-Jan-2024 00:30:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 2.8 {'GRDC'} 07-Jan-2024 00:45:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 10.4 {'GRDC'} 07-Jan-2024 01:00:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 12.9 {'GRDC'} 07-Jan-2024 01:15:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 10.7 {'GRDC'} 07-Jan-2024 01:30:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 7.7 {'GRDC'} 07-Jan-2024 01:45:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 7.7 {'GRDC'} 07-Jan-2024 02:00:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 6.1 {'GRDC'} 07-Jan-2024 02:15:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 6.6 {'GRDC'} 07-Jan-2024 02:30:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 7.7 {'GRDC'} 07-Jan-2024 02:45:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 6.2 {'GRDC'} 07-Jan-2024 03:00:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 6.2 {'GRDC'} 07-Jan-2024 03:15:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 7.7 {'GRDC'} 07-Jan-2024 03:30:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 7 {'GRDC'} 07-Jan-2024 03:45:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 8.4 {'GRDC'}
T1.DateTime = datetime(string(T1.Datum)) + timeofday(datetime(string(T1.Zeit))); % Create & Concatenate Single 'datetime' Array Variable
L = size(T1,1);
TC = T1.Wert;
DT = T1.DateTime;
% return
% L = numel(DT);
TC_Target = 7; % Target Temperature Value
idx = find(diff(TC - TC_Target)); % Indices Of Approximate 'TC_Target' Values
for k = 1:numel(idx)
idxrng = max(1,idx(k)) : min(L,idx(k)+1); % Index Range For Interpolation
[TCu,ixu] = unique(TC(idxrng)); % 'Fudge Factor' To Avoid Non-Unique Temperatures
TE(k) = interp1(TC(idxrng(ixu)), DT(idxrng(ixu)), TC_Target); % Interpolate Temperatures To Get Time
end
TC7_Times = TE(~ismissing(TE)).';
TC7_Times.Format = 'HH:mm:ss.SSSSSS'
TC7_Times = 169×1 datetime array
00:23:53.009708 00:38:17.368421 01:51:33.750000 02:20:27.272727 02:37:00.000000 03:07:59.999999 03:30:00.000000 03:30:00.000000 03:51:10.588235 04:37:07.868852 05:09:05.454545 05:37:29.999999 05:49:45.365853 06:20:40.540540 06:57:02.950819 07:07:30.000000 07:19:36.923076 07:37:47.307692 08:13:03.870967 08:52:00.000000 09:16:43.846153 09:51:47.812500 10:21:06.666666 10:54:20.000000 11:23:16.551724 11:52:30.000000 12:17:30.000000 12:36:49.090909 13:39:22.500000 14:17:08.571428
figure
plot(DT, TC)
hold on
plot(TE, ones(size(TE))*7, 'sr')
hold off
grid
yline(7, '--g')
xlabel('Time')
ylabel('T (°C)')
title('Temperature Data Showing Intercept Times')
figure
plot(DT, TC)
hold on
plot(TE, ones(size(TE))*7, 'sr')
hold off
grid
yline(7, '--g')
xlabel('Time')
ylabel('T (°C)')
title('Temperature Data Showing Intercept Times - Detail')
xlim([datetime(2024,1,8,06,00,00) datetime(2024,1,8,14,00,00)])
I had to tweak the approach that I usually use for these sorts of problems to work with your data.
I am pleased with these results.
EDIT — (12 Feb 2024 at 14:37)
Re-ran my previous code with the data when it posted. Required a minor tweak to my earlier, original code.
.

5 commentaires

Alex
Alex le 12 Fév 2024
Modifié(e) : Alex le 12 Fév 2024
Really sorry i forgot a CSV file. Thank you for the code I'll check if your code helps me. I also added a CSV file for clarification.
So i tried and i get the error: "Sample points must be unique."
Alex
Alex le 12 Fév 2024
Thank you very very much for your help and for showing me a better way to combine my date and time columns.
If I may ask you another question: how would you integrate everything above TC_Target?
As always, my pleasure!
Integrating everything above ‘TC_Target’ would be straightforward except for the independent variable being time here. That required a bit of experimentation because the trapz function (used to do the integration) wants only numerical data, not datetime values. An additional consideration is where the temparatures exceed the ‘TC_Target’ threshold, and here that begins with the second intersection, so the integration loop begins with the second intersection and ends with the last intersection given that there must be an even number of them. I added a pair of if blocks that check for those in order to make this as autonomous as possible. I believe all that now works correctly. This now does everything including the integrations. I also added detail plots at the beginning and end of the data. It took a bit of time to get everything working the way I want it to.
The code —
T1 = readtable('311FT01Temp.csv')
T1 = 384×6 table
Datum Zeit Objektname Parameter Wert Einheit ___________ ________ ______________________________________ ______________ ____ ________ 07-Jan-2024 00:00:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 9.6 {'GRDC'} 07-Jan-2024 00:15:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 13.1 {'GRDC'} 07-Jan-2024 00:30:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 2.8 {'GRDC'} 07-Jan-2024 00:45:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 10.4 {'GRDC'} 07-Jan-2024 01:00:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 12.9 {'GRDC'} 07-Jan-2024 01:15:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 10.7 {'GRDC'} 07-Jan-2024 01:30:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 7.7 {'GRDC'} 07-Jan-2024 01:45:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 7.7 {'GRDC'} 07-Jan-2024 02:00:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 6.1 {'GRDC'} 07-Jan-2024 02:15:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 6.6 {'GRDC'} 07-Jan-2024 02:30:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 7.7 {'GRDC'} 07-Jan-2024 02:45:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 6.2 {'GRDC'} 07-Jan-2024 03:00:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 6.2 {'GRDC'} 07-Jan-2024 03:15:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 7.7 {'GRDC'} 07-Jan-2024 03:30:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 7 {'GRDC'} 07-Jan-2024 03:45:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 8.4 {'GRDC'}
T1.DateTime = datetime(string(T1.Datum)) + timeofday(datetime(string(T1.Zeit))); % Create & Concatenate Single 'datetime' Array Variable
L = size(T1,1);
TC = T1.Wert;
DT = T1.DateTime;
TC_Target = 7; % Target Temperature Value
idx = find(diff(TC - TC_Target)); % Indices Of Approximate 'TC_Target' Values
for k = 1:numel(idx)
idxrng = max(1,idx(k)) : min(L,idx(k)+1); % Index Range For Interpolation
[TCu,ixu] = unique(TC(idxrng)); % Avoid Non-Unique Temperatures
TE(k) = interp1(TC(idxrng(ixu)), DT(idxrng(ixu)), TC_Target); % Interpolate Temperatures To Get Time
slope(k,:) = TC(idxrng(end))-TC(idxrng(1));
end
Lv = ~ismissing(TE);
slope = slope(Lv);
TC7_Times = TE(~ismissing(TE)).';
TC7_Times.Format = 'HH:mm:ss.SSSSSS'
TC7_Times = 169×1 datetime array
00:23:53.009708 00:38:17.368421 01:51:33.750000 02:20:27.272727 02:37:00.000000 03:07:59.999999 03:30:00.000000 03:30:00.000000 03:51:10.588235 04:37:07.868852 05:09:05.454545 05:37:29.999999 05:49:45.365853 06:20:40.540540 06:57:02.950819 07:07:30.000000 07:19:36.923076 07:37:47.307692 08:13:03.870967 08:52:00.000000 09:16:43.846153 09:51:47.812500 10:21:06.666666 10:54:20.000000 11:23:16.551724 11:52:30.000000 12:17:30.000000 12:36:49.090909 13:39:22.500000 14:17:08.571428
start_idx = 1;
if slope(1) < 0
start_idx = 2;
end
if rem(numel(TC7_Times)-start_idx+1, 2) == 0
end_idx = numel(TC7_Times)-1;
end
for k = start_idx : end_idx % Start At Second Intersection
k = k-1; % Correction For Beginning With Second Entry
TI(k,:) = [TC7_Times(k) TC7_Times(k+1)]; % Interval Times
Timev = TI(k,1) : minutes(1) : TI(k,2); % Minutes In Interval
Tempv = interp1(DT, TC, Timev); % Interpolate Temperature In Interval
IntervalDuration(k,:) = numel(Timev); % Interval Curation (Minutes)
T_int(k,:) = trapz((1:numel(Timev)), Tempv); % Units: °C x Minute
end
Time_Temp_Table = table(TI, IntervalDuration, T_int, 'VariableNames',{'Time Interval','Interval Duration (Minutes)','Integrated Temperature (°C x Minute)'})
Time_Temp_Table = 167×3 table
Time Interval Interval Duration (Minutes) Integrated Temperature (°C x Minute) ________________________________ ___________________________ ____________________________________ 00:23:53.009708 00:38:17.368421 15 67.851 00:38:17.368421 01:51:33.750000 74 709.89 01:51:33.750000 02:20:27.272727 29 181.41 02:20:27.272727 02:37:00.000000 17 117.75 02:37:00.000000 03:07:59.999999 32 198.6 03:07:59.999999 03:30:00.000000 23 161.7 03:30:00.000000 03:30:00.000000 1 0 03:30:00.000000 03:51:10.588235 22 161.82 03:51:10.588235 04:37:07.868852 46 223.32 04:37:07.868852 05:09:05.454545 32 277.54 05:09:05.454545 05:37:29.999999 29 167.81 05:37:29.999999 05:49:45.365853 13 91.902 05:49:45.365853 06:20:40.540540 31 160.34 06:20:40.540540 06:57:02.950819 37 346.14 06:57:02.950819 07:07:30.000000 11 63.759 07:07:30.000000 07:19:36.923076 13 91.215
figure
plot(DT, TC)
hold on
plot(TE, ones(size(TE))*7, 'sr')
hold off
grid
yline(7, '--g')
xlabel('Time')
ylabel('T (°C)')
title('Temperature Data Showing Intercept Times')
figure
plot(DT, TC)
hold on
plot(TE, ones(size(TE))*7, 'sr')
hold off
grid
yline(7, '--g')
xlabel('Time')
ylabel('T (°C)')
title('Temperature Data Showing Intercept Times - Detail')
xlim([datetime(2024,1,8,06,00,00) datetime(2024,1,8,14,00,00)])
Ax = gca;
Ax.XMinorTick = 'on';
figure
plot(DT, TC)
hold on
plot(TE, ones(size(TE))*7, 'sr')
hold off
grid
yline(7, '--g')
xlabel('Time')
ylabel('T (°C)')
title('Temperature Data Showing Intercept Times - Start Detail')
xlim([DT(1) DT(1)+hours(4)])
Ax = gca;
Ax.XMinorTick = 'on';
figure
plot(DT, TC)
hold on
plot(TE, ones(size(TE))*7, 'sr')
hold off
grid
yline(7, '--g')
xlabel('Time')
ylabel('T (°C)')
title('Temperature Data Showing Intercept Times - End Detail')
xlim([DT(end)-hours(5) DT(end)])
Ax = gca;
Ax.XMinorTick = 'on';
.
Alex
Alex le 13 Fév 2024
Thank you ever so much for your help. Really interesting to see the train of thought on breaking down the data to make it work. Although I do need to ask why i cannot use "integral" and have to use "trapz".
I have one final question that I am stuck on. I have an additional CSV file with logical 0/1 value which define the time at which the heating is turned on/off. I tried to find the time between turning off and the following peaks, which worked but my attempts to exclude turn off point without a following peak failed so far.
May I ask how you would concatente a defined turnoff point to the following peak (or including your previous help) the following interpolated point if there is one? That is my problem.
Or do i just index everything and if the time between two heating switchpoints does not have a peak ignore that switch and wise versa if there are following peaks without a switchpoint in between ignore the peak?
As always, my pleasure!
The integral function is used to integrate functions, and trapz is used to integrate vectors. Your data are vectors.
This problem requires extracting the necessary data into new table arrays (for efficiency) and then converting those to timetable arrays. The timetable arrays are then combined using the synchronize function to create a single timetable with all the necessary information. After that, it is only necessary to use a bit of the same sort of logic I used previously here to find the next peak following the time the heat is removed. (I assume that the 0 values in the ‘Zust.’ variable mean that the heat is turned off.)
I believe this does what you want —
T1 = readtable('311FT01Temp.csv');
T1.DateTime = datetime(string(T1.Datum)) + timeofday(datetime(string(T1.Zeit))) % Create & Concatenate Single 'datetime' Array Variable
T1 = 384×7 table
Datum Zeit Objektname Parameter Wert Einheit DateTime ___________ ________ ______________________________________ ______________ ____ ________ ____________________ 07-Jan-2024 00:00:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 9.6 {'GRDC'} 07-Jan-2024 00:00:00 07-Jan-2024 00:15:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 13.1 {'GRDC'} 07-Jan-2024 00:15:00 07-Jan-2024 00:30:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 2.8 {'GRDC'} 07-Jan-2024 00:30:00 07-Jan-2024 00:45:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 10.4 {'GRDC'} 07-Jan-2024 00:45:00 07-Jan-2024 01:00:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 12.9 {'GRDC'} 07-Jan-2024 01:00:00 07-Jan-2024 01:15:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 10.7 {'GRDC'} 07-Jan-2024 01:15:00 07-Jan-2024 01:30:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 7.7 {'GRDC'} 07-Jan-2024 01:30:00 07-Jan-2024 01:45:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 7.7 {'GRDC'} 07-Jan-2024 01:45:00 07-Jan-2024 02:00:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 6.1 {'GRDC'} 07-Jan-2024 02:00:00 07-Jan-2024 02:15:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 6.6 {'GRDC'} 07-Jan-2024 02:15:00 07-Jan-2024 02:30:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 7.7 {'GRDC'} 07-Jan-2024 02:30:00 07-Jan-2024 02:45:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 6.2 {'GRDC'} 07-Jan-2024 02:45:00 07-Jan-2024 03:00:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 6.2 {'GRDC'} 07-Jan-2024 03:00:00 07-Jan-2024 03:15:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 7.7 {'GRDC'} 07-Jan-2024 03:15:00 07-Jan-2024 03:30:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 7 {'GRDC'} 07-Jan-2024 03:30:00 07-Jan-2024 03:45:00 {'311FT-FAHRTREPPE01-TEMPERATUR_OBEN'} {'Aktualwert'} 8.4 {'GRDC'} 07-Jan-2024 03:45:00
L = size(T1,1);
TC = T1.Wert;
DT = T1.DateTime;
TC_Target = 7; % Target Temperature Value
idx = find(diff(TC - TC_Target)); % Indices Of Approximate 'TC_Target' Values
for k = 1:numel(idx)
idxrng = max(1,idx(k)) : min(L,idx(k)+1); % Index Range For Interpolation
[TCu,ixu] = unique(TC(idxrng)); % Avoid Non-Unique Temperatures
TE(k) = interp1(TC(idxrng(ixu)), DT(idxrng(ixu)), TC_Target); % Interpolate Temperatures To Get Time
slope(k,:) = TC(idxrng(end))-TC(idxrng(1));
end
Lv = ~ismissing(TE);
slope = slope(Lv);
TC7_Times = TE(~ismissing(TE)).';
TC7_Times.Format = 'HH:mm:ss.SSSSSS'
TC7_Times = 169×1 datetime array
00:23:53.009708 00:38:17.368421 01:51:33.750000 02:20:27.272727 02:37:00.000000 03:07:59.999999 03:30:00.000000 03:30:00.000000 03:51:10.588235 04:37:07.868852 05:09:05.454545 05:37:29.999999 05:49:45.365853 06:20:40.540540 06:57:02.950819 07:07:30.000000 07:19:36.923076 07:37:47.307692 08:13:03.870967 08:52:00.000000 09:16:43.846153 09:51:47.812500 10:21:06.666666 10:54:20.000000 11:23:16.551724 11:52:30.000000 12:17:30.000000 12:36:49.090909 13:39:22.500000 14:17:08.571428
start_idx = 1;
if slope(1) < 0
start_idx = 2;
end
if rem(numel(TC7_Times)-start_idx+1, 2) == 0
end_idx = numel(TC7_Times)-1;
end
for k = start_idx : end_idx % Start At Second Intersection
k = k-1; % Correction For Beginning With Second Entry
TI(k,:) = [TC7_Times(k) TC7_Times(k+1)]; % Interval Times
Timev = TI(k,1) : minutes(1) : TI(k,2); % Minutes In Interval
Tempv = interp1(DT, TC, Timev); % Interpolate Temperature In Interval
IntervalDuration(k,:) = numel(Timev); % Interval Curation (Minutes)
T_int(k,:) = trapz((1:numel(Timev)), Tempv); % Units: °C x Minute
end
Time_Temp_Table = table(TI, IntervalDuration, T_int, 'VariableNames',{'Time Interval','Interval Duration (Minutes)','Integrated Temperature (°C x Minute)'})
Time_Temp_Table = 167×3 table
Time Interval Interval Duration (Minutes) Integrated Temperature (°C x Minute) ________________________________ ___________________________ ____________________________________ 00:23:53.009708 00:38:17.368421 15 67.851 00:38:17.368421 01:51:33.750000 74 709.89 01:51:33.750000 02:20:27.272727 29 181.41 02:20:27.272727 02:37:00.000000 17 117.75 02:37:00.000000 03:07:59.999999 32 198.6 03:07:59.999999 03:30:00.000000 23 161.7 03:30:00.000000 03:30:00.000000 1 0 03:30:00.000000 03:51:10.588235 22 161.82 03:51:10.588235 04:37:07.868852 46 223.32 04:37:07.868852 05:09:05.454545 32 277.54 05:09:05.454545 05:37:29.999999 29 167.81 05:37:29.999999 05:49:45.365853 13 91.902 05:49:45.365853 06:20:40.540540 31 160.34 06:20:40.540540 06:57:02.950819 37 346.14 06:57:02.950819 07:07:30.000000 11 63.759 07:07:30.000000 07:19:36.923076 13 91.215
% figure
% plot(DT, TC)
% hold on
% plot(TE, ones(size(TE))*7, 'sr')
% hold off
% grid
% yline(7, '--g')
% xlabel('Time')
% ylabel('T (°C)')
% title('Temperature Data Showing Intercept Times')
% figure
% plot(DT, TC)
% hold on
% plot(TE, ones(size(TE))*7, 'sr')
% hold off
% grid
% yline(7, '--g')
% xlabel('Time')
% ylabel('T (°C)')
% title('Temperature Data Showing Intercept Times - Detail')
% xlim([datetime(2024,1,8,06,00,00) datetime(2024,1,8,14,00,00)])
% Ax = gca;
% Ax.XMinorTick = 'on';
% figure
% plot(DT, TC)
% hold on
% plot(TE, ones(size(TE))*7, 'sr')
% hold off
% grid
% yline(7, '--g')
% xlabel('Time')
% ylabel('T (°C)')
% title('Temperature Data Showing Intercept Times - Start Detail')
% xlim([DT(1) DT(1)+hours(4)])
% Ax = gca;
% Ax.XMinorTick = 'on';
% figure
% plot(DT, TC)
% hold on
% plot(TE, ones(size(TE))*7, 'sr')
% hold off
% grid
% yline(7, '--g')
% xlabel('Time')
% ylabel('T (°C)')
% title('Temperature Data Showing Intercept Times - End Detail')
% xlim([DT(end)-hours(5) DT(end)])
% Ax = gca;
% Ax.XMinorTick = 'on';
% f = fileread('311FT01Heat.csv')
T2 = readtable('311FT01Heat.csv', 'VariableNamingRule','preserve');
T2.DateTime = datetime(string(T2.Datum)) + timeofday(datetime(string(T2.Zeit)))
T2 = 86×8 table
Datum Zeit MKat Objektname Zust. Meldetext Klartext DateTime ___________ ________ ______ ___________________________________ _____ _______________________ ________ ____________________ 07-Jan-2024 00:21:25 {'BZ'} {'311FT-FAHRTREPPE01-HEIZUNG_OBEN'} 1 {'aktiver_Zustand ein'} NaN 07-Jan-2024 00:21:25 07-Jan-2024 00:25:33 {'BZ'} {'311FT-FAHRTREPPE01-HEIZUNG_OBEN'} 0 {'aktiver_Zustand aus'} NaN 07-Jan-2024 00:25:33 07-Jan-2024 00:29:57 {'BZ'} {'311FT-FAHRTREPPE01-HEIZUNG_OBEN'} 1 {'aktiver_Zustand ein'} NaN 07-Jan-2024 00:29:57 07-Jan-2024 00:34:05 {'BZ'} {'311FT-FAHRTREPPE01-HEIZUNG_OBEN'} 0 {'aktiver_Zustand aus'} NaN 07-Jan-2024 00:34:05 07-Jan-2024 01:21:09 {'BZ'} {'311FT-FAHRTREPPE01-HEIZUNG_OBEN'} 1 {'aktiver_Zustand ein'} NaN 07-Jan-2024 01:21:09 07-Jan-2024 01:25:17 {'BZ'} {'311FT-FAHRTREPPE01-HEIZUNG_OBEN'} 0 {'aktiver_Zustand aus'} NaN 07-Jan-2024 01:25:17 07-Jan-2024 02:08:06 {'BZ'} {'311FT-FAHRTREPPE01-HEIZUNG_OBEN'} 1 {'aktiver_Zustand ein'} NaN 07-Jan-2024 02:08:06 07-Jan-2024 02:12:14 {'BZ'} {'311FT-FAHRTREPPE01-HEIZUNG_OBEN'} 0 {'aktiver_Zustand aus'} NaN 07-Jan-2024 02:12:14 07-Jan-2024 03:09:58 {'BZ'} {'311FT-FAHRTREPPE01-HEIZUNG_OBEN'} 1 {'aktiver_Zustand ein'} NaN 07-Jan-2024 03:09:58 07-Jan-2024 03:14:06 {'BZ'} {'311FT-FAHRTREPPE01-HEIZUNG_OBEN'} 0 {'aktiver_Zustand aus'} NaN 07-Jan-2024 03:14:06 07-Jan-2024 04:26:46 {'BZ'} {'311FT-FAHRTREPPE01-HEIZUNG_OBEN'} 1 {'aktiver_Zustand ein'} NaN 07-Jan-2024 04:26:46 07-Jan-2024 04:41:35 {'BZ'} {'311FT-FAHRTREPPE01-HEIZUNG_OBEN'} 0 {'aktiver_Zustand aus'} NaN 07-Jan-2024 04:41:35 07-Jan-2024 05:49:59 {'BZ'} {'311FT-FAHRTREPPE01-HEIZUNG_OBEN'} 1 {'aktiver_Zustand ein'} NaN 07-Jan-2024 05:49:59 07-Jan-2024 05:54:07 {'BZ'} {'311FT-FAHRTREPPE01-HEIZUNG_OBEN'} 0 {'aktiver_Zustand aus'} NaN 07-Jan-2024 05:54:07 07-Jan-2024 06:24:07 {'BZ'} {'311FT-FAHRTREPPE01-HEIZUNG_OBEN'} 1 {'aktiver_Zustand ein'} NaN 07-Jan-2024 06:24:07 07-Jan-2024 06:30:23 {'BZ'} {'311FT-FAHRTREPPE01-HEIZUNG_OBEN'} 0 {'aktiver_Zustand aus'} NaN 07-Jan-2024 06:30:23
T1r = T1(:, [7 5]) % Create New, Edited 'table' Arrays For This Part
T1r = 384×2 table
DateTime Wert ____________________ ____ 07-Jan-2024 00:00:00 9.6 07-Jan-2024 00:15:00 13.1 07-Jan-2024 00:30:00 2.8 07-Jan-2024 00:45:00 10.4 07-Jan-2024 01:00:00 12.9 07-Jan-2024 01:15:00 10.7 07-Jan-2024 01:30:00 7.7 07-Jan-2024 01:45:00 7.7 07-Jan-2024 02:00:00 6.1 07-Jan-2024 02:15:00 6.6 07-Jan-2024 02:30:00 7.7 07-Jan-2024 02:45:00 6.2 07-Jan-2024 03:00:00 6.2 07-Jan-2024 03:15:00 7.7 07-Jan-2024 03:30:00 7 07-Jan-2024 03:45:00 8.4
T2r = T2(:, [8 5]) % Create New, Edited 'table' Arrays For This Part
T2r = 86×2 table
DateTime Zust. ____________________ _____ 07-Jan-2024 00:21:25 1 07-Jan-2024 00:25:33 0 07-Jan-2024 00:29:57 1 07-Jan-2024 00:34:05 0 07-Jan-2024 01:21:09 1 07-Jan-2024 01:25:17 0 07-Jan-2024 02:08:06 1 07-Jan-2024 02:12:14 0 07-Jan-2024 03:09:58 1 07-Jan-2024 03:14:06 0 07-Jan-2024 04:26:46 1 07-Jan-2024 04:41:35 0 07-Jan-2024 05:49:59 1 07-Jan-2024 05:54:07 0 07-Jan-2024 06:24:07 1 07-Jan-2024 06:30:23 0
TT1r = table2timetable(T1r) % Convert Them To 'timetable' Arrays
TT1r = 384×1 timetable
DateTime Wert ____________________ ____ 07-Jan-2024 00:00:00 9.6 07-Jan-2024 00:15:00 13.1 07-Jan-2024 00:30:00 2.8 07-Jan-2024 00:45:00 10.4 07-Jan-2024 01:00:00 12.9 07-Jan-2024 01:15:00 10.7 07-Jan-2024 01:30:00 7.7 07-Jan-2024 01:45:00 7.7 07-Jan-2024 02:00:00 6.1 07-Jan-2024 02:15:00 6.6 07-Jan-2024 02:30:00 7.7 07-Jan-2024 02:45:00 6.2 07-Jan-2024 03:00:00 6.2 07-Jan-2024 03:15:00 7.7 07-Jan-2024 03:30:00 7 07-Jan-2024 03:45:00 8.4
TT2r = table2timetable(T2r) % Convert Them To 'timetable' Arrays
TT2r = 86×1 timetable
DateTime Zust. ____________________ _____ 07-Jan-2024 00:21:25 1 07-Jan-2024 00:25:33 0 07-Jan-2024 00:29:57 1 07-Jan-2024 00:34:05 0 07-Jan-2024 01:21:09 1 07-Jan-2024 01:25:17 0 07-Jan-2024 02:08:06 1 07-Jan-2024 02:12:14 0 07-Jan-2024 03:09:58 1 07-Jan-2024 03:14:06 0 07-Jan-2024 04:26:46 1 07-Jan-2024 04:41:35 0 07-Jan-2024 05:49:59 1 07-Jan-2024 05:54:07 0 07-Jan-2024 06:24:07 1 07-Jan-2024 06:30:23 0
TT3r = synchronize(TT1r, TT2r) % Use 'synchronize' To Combine The 'timetable' Arrays With A Common Time Reference
TT3r = 470×2 timetable
DateTime Wert Zust. ____________________ ____ _____ 07-Jan-2024 00:00:00 9.6 NaN 07-Jan-2024 00:15:00 13.1 NaN 07-Jan-2024 00:21:25 NaN 1 07-Jan-2024 00:25:33 NaN 0 07-Jan-2024 00:29:57 NaN 1 07-Jan-2024 00:30:00 2.8 NaN 07-Jan-2024 00:34:05 NaN 0 07-Jan-2024 00:45:00 10.4 NaN 07-Jan-2024 01:00:00 12.9 NaN 07-Jan-2024 01:15:00 10.7 NaN 07-Jan-2024 01:21:09 NaN 1 07-Jan-2024 01:25:17 NaN 0 07-Jan-2024 01:30:00 7.7 NaN 07-Jan-2024 01:45:00 7.7 NaN 07-Jan-2024 02:00:00 6.1 NaN 07-Jan-2024 02:08:06 NaN 1
figure
hp = plot(TT3r.DateTime, TT3r{:,1}, 'DisplayName','Temperature (°C)');
grid
Lv_Zust = (TT3r.('Zust.') == 0); % Logical Index Vector
hx = xline(TT3r.DateTime(Lv_Zust), '-r', 'DisplayName','activer Zustand aus'); % 'on' Times
xlim([TT3r.DateTime(1) datetime(2024,01,08,05,00,00)])
xlabel('Date & Time')
ylabel('°C')
legend([hp hx(1)], 'Location','northoutside','Orientation','horizontal')
idx_Zust = find(Lv_Zust); % Numerical Index Vector
for k = 1:numel(idx_Zust)-1
idxrng = idx_Zust(k) : idx_Zust(k+1); % Search Region: Heat Off Index(k) To Heat Off Index(k+1)
[Tmax(k,:),idx] = max(TT3r.Wert(idxrng)); % Maximum Temperature In Index Range
Tmaxidx(k,:) = idx_Zust(k) + idx; % Index (Used To Find Time)
DT_Temp(k,:) = TT3r.DateTime(Tmaxidx(k)); % Maximum Temperature Time
DT_Zust(k,:) = TT3r.DateTime(idx_Zust(k)); % Heat Off Time
end
elapsed_time = DT_Temp - DT_Zust;
Results = table(DT_Zust, DT_Temp, elapsed_time, Tmax, 'VAriableNames',{'Heat Off Time','Next Peak Temparature Time','Elapsed Time','Next Peak Temperature (°C)'})
Results = 42×4 table
Heat Off Time Next Peak Temparature Time Elapsed Time Next Peak Temperature (°C) ____________________ __________________________ ____________ __________________________ 07-Jan-2024 00:25:33 07-Jan-2024 00:34:05 00:08:32 2.8 07-Jan-2024 00:34:05 07-Jan-2024 01:15:00 00:40:55 12.9 07-Jan-2024 01:25:17 07-Jan-2024 01:45:00 00:19:43 7.7 07-Jan-2024 02:12:14 07-Jan-2024 02:45:00 00:32:46 7.7 07-Jan-2024 03:14:06 07-Jan-2024 04:00:00 00:45:54 8.4 07-Jan-2024 04:41:35 07-Jan-2024 05:00:00 00:18:25 10.2 07-Jan-2024 05:54:07 07-Jan-2024 06:30:23 00:36:16 9.3 07-Jan-2024 06:30:23 07-Jan-2024 07:00:00 00:29:37 11.9 07-Jan-2024 07:36:32 07-Jan-2024 07:49:28 00:12:56 9.5 07-Jan-2024 07:53:35 07-Jan-2024 08:15:00 00:21:25 12.4 07-Jan-2024 08:53:20 07-Jan-2024 09:15:00 00:21:40 10.2 07-Jan-2024 09:55:12 07-Jan-2024 10:15:00 00:19:48 10.5 07-Jan-2024 10:59:13 07-Jan-2024 11:15:00 00:15:47 8.7 07-Jan-2024 11:52:33 07-Jan-2024 12:15:00 00:22:27 9.7 07-Jan-2024 12:45:53 07-Jan-2024 13:15:00 00:29:07 8.9 07-Jan-2024 13:22:10 07-Jan-2024 13:35:06 00:12:56 9.5
I commented-out the (currently irrelevant) plots from my previous code, however I imported most of that code because that information is necessary here. The new file is a bit easier to work with. (If you want to extract the hours, minutes, and seconds from duration values, you will need to use the hms function. Regular datetime functions do not work with duration arrays.)
.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Operators and Elementary Operations dans Centre d'aide et File Exchange

Produits

Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by