for loop to repeat specified number of times

1 vue (au cours des 30 derniers jours)
Tuba Arif
Tuba Arif le 18 Sep 2020
Modifié(e) : Alan Stevens le 18 Sep 2020
I have 40448x20 matrix. I need to extract 1st 9 rows in one loop iteration, next 9 rows in second iteration and so on.and store each iteration output to perform some calculation.

Réponse acceptée

Alan Stevens
Alan Stevens le 18 Sep 2020
If M is your 40448x20 matrix then something like
for i = 1:9:40448
K = M(i:i+8,:);
... other calculations with K
end
Since 40448 is not exactly divisible by 9 this will leave a few rows of M untouched at the end. You will have to deal with them separately.
  5 commentaires
Alan Stevens
Alan Stevens le 18 Sep 2020
Oh yes! I guess you'll have to do the extra calculations within the loop! At the moment I'm not sure how to save the K's individually (though why would you want to, as you have all the numbers in the large matrix anyway?).
Alan Stevens
Alan Stevens le 18 Sep 2020
Modifié(e) : Alan Stevens le 18 Sep 2020
You could use a structure to store the smaller matrices:
c = 1;
for i = 1:9:40448
K(c).m = M(i:i+8,:);
c = c+1;
... other calculations with K
end
K is now a structure
Access by K(1).m, or K(2).m etc.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by