필터 지우기
필터 지우기

Smallest interval in array

조회 수: 2 (최근 30일)
Pesach Nestlebaum
Pesach Nestlebaum 2022년 4월 27일
댓글: Star Strider 2022년 4월 29일
Hi everyone,
I am attempting to write software that organizes data from a machine that gets triggered multiple times throughout the day. I need to find which times in the day have the highest rate of triggering. In other words, how do I find the intervals with the smallest gaps in time within the data list?
The .xlsx list is attached.
Each row on the list represents an "encounter", and the machine takes a reading of the current time, temp, weight and light level. I need to find out what time interval has the highest rate of triggers.
Any ideas where to start?
Thanks in advance!
  댓글 수: 2
Jan
Jan 2022년 4월 27일
Start with importing the Excel file to Matlab. Which Matlab version are you using?
Then define, what you exactly want to solve: Are you really looking for the shortest distance between the time values in the 1st column? Or does "interval with highest rate" mean e.g. a certain interval of e.g. 2 hours, which contains the highest number of events? Do the numbers in the other columns matter?
Pesach Nestlebaum
Pesach Nestlebaum 2022년 4월 27일
Thanks for answering,
I imported the data already and separated the other columns for later use. That's a great clarification, I guess I am looking for a two hour interval with the highest rate of events.
Ultimately, i'd like the software to determine which times of the day are the most active for any set of data it receives, not this specific list, and keep a log for a monthly average. But this is a good start.

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

채택된 답변

Star Strider
Star Strider 2022년 4월 27일
I am not certain what the desired result is here.
Try this —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/980625/enc_data_samp.xlsx', 'VariableNamingRule','preserve')
T1 = 59×4 table
Time Light Weight Temp ________ _____ ______ ____ 0.04375 1 450 52 0.069444 0 988 52 0.091667 1 633 53 0.14722 1 68 54 0.16667 2 77 55 0.20833 2 540 58 0.22431 4 406 57 0.23681 4 105 58 0.24306 4 100 60 0.25 5 46 62 0.27014 6 79 63 0.29375 7 102 63 0.29583 7 343 63 0.30208 7 76 65 0.30417 7 89 65 0.30486 7 68 65
Tt = cumsum([0; T1.Time]); % Create Time Vector
Td = diff([0; 0; T1.Time])+eps; % Differences Between Trigger Events
Fr = 1./Td; % Frequency Of Trigger Events
figure
plot(Tt, Td)
grid
xlabel('Time')
ylabel('Trigger Frequency')
I am not certain what the time vector (the independent variable here) actually is (I suspect that it should be ‘time of day’ or something similar), however this is likely the easiest way to determine the frequency of the trigger events as a function of it.
.
  댓글 수: 8
Pesach Nestlebaum
Pesach Nestlebaum 2022년 4월 29일
One last question:
This code produces a variable "idx" which is equal to a single number: 8. This seems to be because there is only one column of time data being processed.
Suppose there were 7 columns of time entries instead of just one, how would i produce an array with all 7 idx values? In other words, say there were 7 days of data, each day had different number of triggers. Can I accomplish this with a for loop? Obviously I need it to be coded, not manually updating the list every time.
Thanks!
Star Strider
Star Strider 2022년 4월 29일
As always, my pleasure!
The ‘idx’ variable is simply the row number of the ‘Trigger’ tally maximum. It can be used to refer to the entire row of the timetable, whatever the timetable contains, so:
maxTriggerRow = TT1c{idx,:}
to display all the variables in that row, or equivalently:
maxTriggerRow = TT1c(idx,:)
to display them with their variable names as well (note the difference between the curly braces {} and parentheses ()).
Here, it just happened to also be equivalent to the hour, and the fprintf statement referred to it as such.

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

추가 답변 (1개)

Thomas Pursche
Thomas Pursche 2022년 4월 27일
Hello Pesach,
when I understood it correctly please find in the following a first approach. Just read in the table, get the specific column and afterwards calculate the distances and minimal entry. Afterwards you can put them into an interval and count them if you want to.
% read in the table
tableData = readtable('enc_data_samp.xlsx');
% access intersting column
timeColumn = tableData.Time;
% calculate distance between each entry
for ii=1:numel(timeColumn)-1
distanceList(ii) = timeColumn(ii+1)-timeColumn(ii);
end
% get the minimal distance
minimalDistance = min(distanceList);
Best regards,
Thomas
  댓글 수: 1
Pesach Nestlebaum
Pesach Nestlebaum 2022년 4월 27일
Thank you! This is what I needed in terms of finding all the distances between each entry. how can I now fin which hour has the most entries aka the shortest overall distance if all the distances within that hour are summed up?

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

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by