Filter löschen
Filter löschen

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

13 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

Chunru
Chunru am 2 Aug. 2021
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 Kommentare
German Laster
German Laster am 2 Aug. 2021
Code works perfectly!
Thank you very much!
German Laster
German Laster am 2 Aug. 2021
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...

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays 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!

Translated by