# How to find stable temperature in each days?

1 view (last 30 days)
Sarlota Duskova on 4 Oct 2020
Edited: Sarlota Duskova on 18 Oct 2020
Hello, I am using Matlab R2020b and I am working in App designer. I have data of temperature with two decimals for each days. So the file with name Temperature.xls have one column with date and time and anothers columns is with temperature. I would like to find stable temperature for each days with difference 0 - 0,01. That will be at evening I think something from 20:00 to 7:00 oclock at the morning. Then I want to pick date and time when start and end this interval with stable temperature and take data from another file (data.csv) where is one column also with date and time. So I think that if I have interval with stable temperature I will use ismember or something like that for finding same date and time from another file. But I dont know how to find stable temperature for each days. I tryed this code but it doesnot good solution and I dont have any another idea, so I will be thankfull for any ideas. I am reading data by uigetfile and show them in UITable. Then I am taking this data from UITable and then working with them. I did difference of temperature then I try to find rows when the temperature is for 30 times same and then I try find end of this interval by finding big differences.
T2 = getappdata(app.UITable, 'Data');
TT = table2timetable(T2); %Convert table to timetable
difference = diff(TT.M01__C);
rnd = round(difference, 2, "decimals");
tol = (abs(rnd) <= 0.01);
% Length of each group of consecutive 1s
B = diff(find([0;tol(:);0]==0))-1;
B(B==0) = [];
% Index of 1st '1' in each group of consecutive 1s
firstIdx = find(diff([0;tol(:)])==1);
% Index of last '1' in each group of consecutive 1s
%lastIdx = find(diff([0;tol(:)])== -1);
% Row number of the first 1 in groups of 30 or more consecutive 1s
minConsec = 30;
firstRows = firstIdx(B >= minConsec)
%lastRows = lastIdx(B >= minConsec)
pickStartTime = TT.DATE_(firstRows-1);
timeStartExcel = timeofday(pickStartTime);
filtertime1 = app.TimestartEditField.Value; %Get value from EditField
TimeStart = duration(filtertime1,'Format','hh:mm'); %Convert data from EditField to duration of time
timeStarted = (timeStartExcel >= TimeStart)
bigDiff = (abs(rnd) > 0.2);
% Length of each group of consecutive 1s
C = diff(find([0;bigDiff(:);0]==0))-1;
C(C==0) = [];
% Index of last '1' in each group of consecutive 1s
lastIdx_bigDiff = find(diff([0;bigDiff(:)])== -1);
% Row number of the first 1 in groups of 30 or more consecutive 1s
minConsec_bigDiff = 1;
lastRows_bigDiff = lastIdx_bigDiff(C >= minConsec_bigDiff)
pickLastTime = TT.DATE_(lastRows_bigDiff-1);
timeEndExcel = timeofday(pickLastTime);
filtertime2 = app.TimeendEditField.Value; %Get value from EditField
TimeEnd = duration(filtertime2,'Format','hh:mm'); %Convert data from EditField to duration of time
timeEnded = (timeEndExcel <= TimeEnd)
first1 = find(timeEnded, 1, 'first') % Find first 1 in logical array
pickCorrectLastTime = pickLastTime(first1-1) % Pick correct value
t2 = dateshift(TT.DATE_,'start','day'); % Recognize new day

Ashish Mishra on 13 Oct 2020
Its showing error in data type in converting table to timetable.( error using table2timetable First argument must be a table ) because there is no as such entries ‘Data’ in the .xls file that can be passed as argument in getappdata function.https://www.mathworks.com/help/matlab/ref/getappdata.html.
Sarlota Duskova on 13 Oct 2020
It is not whole code I am using uigetfile and then I am reading data from UITable

R2020b

### Community Treasure Hunt

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

Start Hunting!

Translated by