Smallest interval in array
3 views (last 30 days)
Show older comments
Pesach Nestlebaum
on 27 Apr 2022
Commented: Star Strider
on 29 Apr 2022
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 Comments
Jan
on 27 Apr 2022
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?
Accepted Answer
Star Strider
on 27 Apr 2022
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')
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 Comments
Star Strider
on 29 Apr 2022
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.
More Answers (1)
Thomas Pursche
on 27 Apr 2022
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
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!