count every ten seconds

1 view (last 30 days)
hello this is my Excel file that im trying to work with using matlab (my file is in desktop)
i am trying to sort every ten seconds in (cloumn 11) into a new clomn (12)
my data as you can see range from 1 to 71658 and it contains the date and time as a string
here is an example of what i am trying to do
for i = 1 to 71658
while (the cell value which contains the seconds in cloumn 11 %10 !=0)
count = how many times the word "chew" appears in cloumn 3
print count in cloumn 13
else
sum = sum+1
print sum in cloumn 12
end
how can i write this code using matlab please help me i am desprate
  1 Comment
Walter Roberson
Walter Roberson on 4 Sep 2021
? That file only has 10 columns ?
Column 3 is numeric and never has the word "chew" ??

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 4 Sep 2021
Edited: Walter Roberson on 4 Sep 2021
What do you want to do with the '?chew?' entries?
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/728984/bat11.xlsx';
opt = detectImportOptions(filename);
opt = setvartype(opt, 3, 'categorical');
T = readtable(filename, opt);
ident = T{:,4};
times = T{:,10};
TT = timetable(ident, 'rowtimes', times);
NT = retime(TT, 'regular', @(I) nnz(ismember(I,'Chew')), 'TimeStep', seconds(10));
NT(1:20,:)
ans = 20×1 timetable
Time ident ____________________ _____ 11-Jun-2017 13:09:00 0 11-Jun-2017 13:09:10 0 11-Jun-2017 13:09:20 0 11-Jun-2017 13:09:30 0 11-Jun-2017 13:09:40 0 11-Jun-2017 13:09:50 0 11-Jun-2017 13:10:00 6 11-Jun-2017 13:10:10 18 11-Jun-2017 13:10:20 6 11-Jun-2017 13:10:30 28 11-Jun-2017 13:10:40 54 11-Jun-2017 13:10:50 54 11-Jun-2017 13:11:00 28 11-Jun-2017 13:11:10 26 11-Jun-2017 13:11:20 54 11-Jun-2017 13:11:30 46
If you look through the file from the beginning, you might be led to expect that the values should mostly be 0. However, when you get to row 20010 then the times reset and start to appear more densely, and there are no non-empty column 4s until that point.
Your outlined algorithm would not have worked, as you did not account for the possibility of time being reset.
I do not understand about your column 12 / column 13 desired outputs. Column 13 is expected to contain the count for the block of 10 seconds, but only for the entries where the time is exactly a multiple of 10 and should e empty otherwise? And column 12 should be empty on the places where column 13 is filled in, but on the other lines, it should be a running total of the number of times something other than 'Chew' was found ?? But if so then how do you want to handle the fact that time reset at 20010 ? Or the fact that none of the timestamps in column 10 have seconds that are exact multiples of 10 ?
  5 Comments
Walter Roberson
Walter Roberson on 4 Sep 2021
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/728984/bat11.xlsx';
opt = detectImportOptions(filename);
opt = setvartype(opt, 3, 'categorical');
T = readtable(filename, opt);
ident = T{:,4};
times = T{:,10};
TT = timetable(ident, 'rowtimes', times - times(1));
NT = retime(TT, 'regular', @(I) [nnz(ismember(I,'Chew')), nnz(ismember(I,'con'))], 'TimeStep', seconds(10));
NT(1:20,:)
ans = 20×1 timetable
Time ident ________ _________ 00:00:00 0 258 00:00:10 0 168 00:00:20 0 10 00:00:30 0 0 00:00:40 0 0 00:00:50 0 0 00:01:00 6 0 00:01:10 18 0 00:01:20 14 124 00:01:30 26 172 00:01:40 62 102 00:01:50 48 86 00:02:00 22 2 00:02:10 44 12 00:02:20 56 116 00:02:30 48 8

Sign in to comment.

More Answers (1)

grace khashman
grace khashman on 7 Sep 2021
THANK YOU SOOO MUCH :)

Community Treasure Hunt

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

Start Hunting!