Sliding window with 40 window size and 25%(10) overlap on the cell array

14 次查看(过去 30 天)
Hello,
I have an cell array of size 3765x1(Accelerometer Data) each row contain an double array with same column size and different row size(ex. 1) 230x40, 2) 260x40, 3) 195x40 .... 3965) 312x40).
I want to apply overlap moving window with window size = 40 and 25% overlap to each of this sub-arrays. For example, in the case of 230x40 array I should approximately obtain 7 new square arrays(40x40) and remaining rows should be added to the next 260x40 array and so on. from the last 3965 array I want to remove all the remaining rows.
In the case of 230x40 => 1)(1-40)x40, 2) (30-70)x40, 3) (60-100)x40 ect.
As a result I want to get new cell array of size ~38658 containing only 40x40 square arrays obtained from above.
This is my code, but it doesn't work as i would:
Version1:
%Here fcell is cell array of size 3965x1
n_window = 40;
overlap_win=10;
for i = 1:length(fcell)
max_count = ceil((length(Acc{i,1})-n_window)/(n_window-overlap_win))+1;
for k = 1:max_count
for ii = 1:length(Acc{i,1})
new_data{k,1} = Acc{i,1}(1:length(CalAccGyr{i,:}(ii,:)),:)' + (1:n_window);
end
end
end
After overlap sliding window process, this cell array should not be 3965x40...
Version2:
count = 0;
for i = 1:length(fcell)
for j = 1:10:length(Acc{i,1})-40
count = count+1;
new_data{j,1} = Acc{i,1}(j+1:40+j)' + (1:40);
end
end
Version3:
n_window = 40;
overlap_win=10;
for i = 1:length(fcell)
N_max=length(Acc{i,1});
max_count = ceil((length(CalAccGyr{i,1})-n_window)/(n_window-overlap_win))+1;
n_start=1;
for count = 1:max_count
%new_data{count,1} = new_data{count,1}(max_count,n_window);
n_end = n_start + n_window - 1;
if n_end > N_max
new_data{count,1} = Acc{i,1}(n_start:N_max);
else
new_data{count,1} = Acc{i,1}(n_start:n_end);
end
n_start = n_end-overlap_win;
end
end
Please help me figure this out...
Thank you.

采纳的回答

Chunru
Chunru 2021-8-2
Version 4:
% Creat some data
ns = randi([10,50], 30, 1); % number of samples for 30x1 cell elements
x = cell(length(ns), 1);
for i = 1:length(ns)
x{i} = randn(ns(i), 4); % use 4 instead 40 for a small example
end
% contact x into an array
x = cell2mat(x);
nwin = 10; noverlap = 4;
hopSize = nwin - noverlap;
nblocks = fix((size(x, 1)-noverlap)/hopSize);
coloffsets = (0:(nblocks-1))*hopSize;
% For uniform data, use array instead of cells for speed and efficiency
xout = zeros(nwin, 4, nblocks);
for i=1:nblocks
xout(:, :, i) = x((i-1)*hopSize+(1:nwin), :);
end
  2 个评论
German Laster
German Laster 2021-8-2
My end goal is using this data array as an input to my early prepared NN model, so I need input array of specific size. (Now, I got "40x40xlarge number that can't be divided by 3 without remainder, ex.35000)".
Sir, if it doesn't bother you too much, can you help me to transfer this 3D matrix to 4D of size 40x40x3xsomething? I tried to use:
xout(40,40,3,end)
But something went wrong, and I got too many zero values...

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by