Count variables in a column over a moving window
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi all,
I am working on validating an algorithm and do so I am essentially calculating the number of "column A" = "column B", on a second by second time frame, where each row is assigned to a second.
However, I am finding the results do not indicate the true accuracy because the number observed (column B) may be correctly predicted (column A) but are not aligned on the same row (more than likely one second off usually).
I know you can do:
A = count(str,"standing")
or
idx = strfind(testmodelLF1sec, 'Standing');
idx = find(not(cellfun('isempty', idx)));
NStanding = length(idx)
And during my algorithm development I was able to calculate moving means, median, std etc.
Is there a way to calculate a moving calculation to count the number of times each of my 6 variables appears in a moving window of 30 or 60 seconds?
Hope this makes sense. Any help is much appreciated!
Thankyou,
Katrina
0 Kommentare
Antworten (1)
Sammit Jain
am 28 Jan. 2020
Hello Katrina,
Since I couldn't find any sample data in the query, let's consider you have 2 string arrays which look something like this:
str1 = ["standing", "sitting", "walking", "standing", "standing", "standing", "sitting", "standing", "sitting", "walking"];
str2 = ["sitting", "sitting", "walking", "walking", "walking", "standing", "standing", "standing", "sitting", "walking"];
Considering only 3 categories, and arrays of length 10. Now, let us do a sample calculation for a moving window of 3 seconds. Assuming that the intention here is to match each element of str2 within a moving window of 3 samples. Better to have an odd number for the window-size for a uniform convolution-like operation. For example, if str2(2) which is "sitting" is considered, then for a window of 3, it will be compared to str1(1), str1(2) and str1(3). The output being [0 1 0]
window_size = 3;
half_window = floor(window_size/2);
% First element compared to only elements of the right half of the window
countS = sum(count(str1(1:half_window+1),str2(1)))
% All the middle elements compared to element numbers i-1, i and i+1
for i = 2:length(str1)-1
countS = sum(count(str1(i-1:i+1)))
end
% The final element compared to only elements of the left half of the window
countS = sum(count(str1(end-half_window:end),str2(end)))
Hope this helps.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Dates and Time finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!