moving array in a vector

1 次查看(过去 30 天)
FaridE
FaridE 2023-2-14
回答: Shushant 2023-2-15
Hi all, I need your kind support as I really confused to write moving array, let say for a simplified example i have an array vector of,
H = [1 2 3 4 5 6]
with the bracket of array is size of 4 elements.
The first bracket display, J1 = [1,2,3,4]
Then, it move, J2 = [2,3,4,5]
Then, it move further to end, J3 = [3,4,5,6]
Thank you very much in advance.
  1 个评论
Rik
Rik 2023-2-14
You want to implement your own version of functions like movmean, movstd, etc? Why exactly? And what have you tried?

请先登录,再进行评论。

回答(1 个)

Shushant
Shushant 2023-2-15
According to the example provided by you I have made a small code snippet which simulates the moving array. I hope this solves your confusion.
H = [1 2 3 4 5 6];
bracket = 4;
J={};
for x = 1:size(H,2)-bracket+1 % run till element whose index + bracket is less than the size of vector H.
J{x} = H(x:bracket+x-1); % store elements in bracket to the variable J.
end
J
J = 1×3 cell array
{[1 2 3 4]} {[2 3 4 5]} {[3 4 5 6]}

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by