Storing a forloop in a matrix
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Melissa2305
am 6 Dez. 2015
Kommentiert: Melissa2305
am 6 Dez. 2015
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 Kommentare
Akzeptierte Antwort
Geoff Hayes
am 6 Dez. 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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!