MATLAB: How to select 5 rows of a data set in rolling basis

programmingrandom

I have a price data of 4 stocks for 2000 days. Hence, the data is of 2000 rows and 4 columns. I want to select first 5 rows and then use "randperm" to rearrange the data randomly and just save the prices of first day according to the "randeperm" arrangement.
I have to repeat the process till 2000 rows in rolling basis. That means I have to take 2-6 rows next and then use "randperm" and so on.

Best Answer

A=randi(9,20,4)
n=size(A,1);
for k=1:n-4
a=A(k:k+4,:);
A(k:k+4,:)=a(randperm(5),:);
end