count every ten seconds
4 views (last 30 days)
Show older comments
grace khashman
on 3 Sep 2021
Answered: grace khashman
on 7 Sep 2021
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
on 4 Sep 2021
Edited: Walter Roberson
on 4 Sep 2021
? That file only has 10 columns ?
Column 3 is numeric and never has the word "chew" ??
Accepted Answer
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,:)
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
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,:)
More Answers (1)
See Also
Categories
Find more on Data Type Conversion 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!