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
Edited: 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

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

hello and thank you soo much
as you can see in the file i have a cloumn (J) that conatins the date and time im trying to sort every ten seconds into a new one in other words i want matlab to tell me which ten seconds are these in cloumn (k) : if in cloumn k apears number one that means that these are the first ten seconds
if in cloumn (k) apears number 10 that means that these are the tenth' ten seconds
and on the way by telling me which ten seconds are these it have to write me in cloumn (L) how many times the word chew appeard in cloumn (d)
sorry about the missunderstanding what i was trying to do was to sort every block of ten seconds without anylimits every block contains just ten seconds
the first block is the first ten seconds ------ so in cloumn (k) apears number one and in cloumn (L) appears how many times did the word "chew" (thats the input in this cloumn) and in cloumn (M) apears how many times did the word "con" apears
the second block is the second ten seconds -------- so in cloumn (k) appears number two and the same for the word chew and con
When you talk about "the first 10 seconds" do you mean "calendar seconds", so to speak -- that is, read the seconds out of the datetime in the column? So if the first entry in the file happened to have a time with :23.185 then that would be part of the group starting from :20.000 and ending at :29.999 ?
Or do you want everything relative to the first time in the file, subtracting the first time from all other times to get relative times?
Or do you want everything relative to the lowest time in the file, which might be at row 20010 because the times reset ?
i want everything relative to the last cloumn in my file. and what i mean by the first ten seconds are the seconds from the first cell (:03) to (:13) these represent the first block
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)

Community Treasure Hunt

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

Start Hunting!