How to make a loop that performs the same operation on a large matrix ?

2 visualizzazioni (ultimi 30 giorni)
I know this will have been asked before, but I can't seem to work out the answer after quite a lot of hours of searching; if someone could help I'd be really greatful
I have a matrix that is 64 x 149 (64 rows, 149 columns)
I would like to work out the mean and variance for groups of three rows, going down by one each time
So, rows 1, 2 and 3, then rows 2, 3 and 4, rows 3, 4 and 5 etc...
I'm sure there must be some way of doing this other than manually imputting it for every single calculation - perhaps using a for loop? But as to actually make this work I'm somewhat lost.
Apologies for my ineptitude; if anyone could help I would be so greatful!!

Risposta accettata

David Hill
David Hill il 13 Ago 2020
for k=1:62
m(k)=mean(yourMatrix(k:k+2,:),'all');
v(k)=var(yourMatrix(k:k+2,:),1,'all');
end

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by