Hello, I am using MATLAB 2020b and I would like to find same temperature in night for each days. I am reading data by readtable. This code is for finding data in night from 00:00 to 7:00 oclock morning.
T2 = getappdata(app.UITable, 'Data');
TT = table2timetable(T2); %Convert table to timetable
filtertime1 = app.TimestartEditField.Value; %Get value from EditField
TimeStart = duration(filtertime1,'Format','hh:mm'); %Convert data from EditField to duration of time
filtertime2 = app.TimeendEditField.Value; %Get value from EditField
TimeEnd = duration(filtertime2,'Format','hh:mm'); %Convert data from EditField to duration of time
pickStartTime = TT.DATE_(:);
timeStartExcel = timeofday(pickStartTime);
idx = (timeStartExcel >= TimeStart) & (timeStartExcel < TimeEnd);
T2 = TT(idx,:);
But here, I need to find same temperature, I tryed use unique but it doesnot find same temperature for each days.
[C,IA,IC] = unique(T2.M01__C);
B = T2(IA,:);
Temperature = retime(B,'daily');
Or is it there some option how to use for cycle? Like I have start point for example temperature 22,0°C and I will compare for each days that is it same?
count = 0;
for i = 1:numel(T2)
temperature(i) = 22,00 + i;
if T2.M01__C(i,1) == temperature;
count = count +1;
end
end
Temperature_matlab is file with data I am using. This file is just as an example, the same temperature for each days is 18,05 ° C. I would like to find if the same temperature for each days exist or if doesnot which temperature will be most common and which days it will be.

댓글 수: 6

Mario Malic
Mario Malic 2020년 10월 24일
Unique removes the same values and sorts the data. You can try ismember function.
I tryed to separate days and find unique temperature for each days so now I have array that contains days with unique temperature.
h = unique(T2.DATE_.Day); %Find unique days
c = cell(length(h),1);
for i = 1:length(c)
c{i} = T2(T2.DATE_.Day == h(i),:);
separateTables = c{i,:};
[C,IA,IC] = unique(separateTables.M01__C); %Find unique temperature
uniqueTemperature{i} = separateTables(IA,:);
Temperature{i} = uniqueTemperature.M01__C;
end
Now I tried to use ismember but i don't know how to find which temperature is most repeated
for j = 1:length(c)
for k = 1:length(c)
table1 = uniqueTemperature{1,j}
table2 = uniqueTemperature{1,k}
sameTemp = ismember(table1.M01__C,table2.M01__C)
end
end
Or maybe use for loop but I need to solve somehow indexing to doubles in cell array.
count = 0;
max = 0;
for j = 1:length(c)
B = cell2mat(Temperature(j,j))
for k = 1:length(c)
C = cell2mat(Temperature(j,k))
day1 = B(j,1)
day2 = C(k,1)
if day1 == day2
count = count + 1
if j == 0
max = count
topID = 0
else
count > max
topID = k
end
end
end
end
Mario Malic
Mario Malic 2020년 10월 26일
ismember returns true or false whether the element you're looking for is in the variable you're testing it against.
Disclaimer: I haven't used the functions below.
Your temperatures are in table, maybe groupcounts would be useful.
For the most occurence temperatures you can use histcounts, histcounts2 (for each day), and histogram, histogram2 for graphical plots. If you set number of bins equal to the length of the vector with unique values, you probably will get what you're looking for.
Sarlota Duskova
Sarlota Duskova 2020년 10월 26일
Thank you for your help. First time I tried histcounts but maybe I dont understood corectly how to use it so I tried groupcounts and it works great. I found the most common occurrence of the same temperature.
allDays = vertcat(uniqueTemperature{1,:});
G = groupcounts(allDays,'M01__C')
maxVal = max(G.GroupCount);
idx = find(G.GroupCount == maxVal);
allTemp = G(idx,:)
Sarlota Duskova
Sarlota Duskova 2020년 10월 26일
How can I marked this answer as accepted please?
Mario Malic
Mario Malic 2020년 10월 26일
편집: Mario Malic 2020년 10월 26일
Comments can't be accepted as an answer. I posted a brief reply that you can accept. Thanks in a advance, have a great start of the week!

댓글을 달려면 로그인하십시오.

 채택된 답변

Mario Malic
Mario Malic 2020년 10월 26일
편집: Mario Malic 2020년 10월 26일

0 개 추천

See discussion in the comments section, groupcounts function works well with data in the table.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Tables에 대해 자세히 알아보기

질문:

2020년 10월 22일

편집:

2020년 10월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by