MATLAB: Divide a matrix into small matrices with equal number of columns using “for” loop

for loopMATLABmatrix

I have a matrix with size 1*2809 . I want to loop the matrix and take 8 values at a time to perform element wise multiplication with another 8 bit size matrix. Either, what i want to do is divide the matrix, such that in the first iteration only the first 1:8 elements are taken, and, in second iteration, 8:16 elements are taken and so on.
How can I achieve this in matlab using "for" loop.

Best Answer

A for-loop is unnecessary. If A is the matrix you are trying to divide up into groups of 8 and B is the 8-vector you are multiplying them with, then do
C=reshape(A,8,[]).*B(:);
C=C(:).';
However, 92609 is not a multiple of 8, so fix that first.