Storing a forloop in a matrix
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi!
I am writing an optimization script at the moment, but encountered a problem. I am using a for-loop and I want it to store the result in one matrix. However, it overwrites the previous results, and therefore only presents one row as a result in the end.
My basic script:
data = xlsread('coal.xlsx', 'C2:C121')';
for ii=1:40
Rows = zeros(40,3);
Rows (ii,:) = data (ii:40:120)
end
Thanks in advance!
0 commentaires
Réponse acceptée
Geoff Hayes
le 6 Déc 2015
Melissa - initialize Rows outside of the for loop because you are just overwriting all those values from previous iterations with zeros whenever you re-instantiate it at the first line of your for loop. Try
Rows = zeros(40,3);
for ii=1:40
Rows (ii,:) = data (ii:40:120)
end
Though I'm not sure that is exactly what you will need since it is unclear on the dimensions of data.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements 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!