Storing values from a nested FOR loop (can't get how to save the output into a matrix)
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
ZenithWoman
am 7 Dez. 2016
Kommentiert: ZenithWoman
am 7 Dez. 2016
- I am new to coding so pardon me if this questions seems to easy to be asking but I have already spent hours searching online*
I have an 80 column matrix. I want to write a loop that takes the average of 1st item and the 11th item and in that order till the average of 70th and 80th item.I should have 40 columns in the end. I was able to write the loop to do that but because I can't get the output of each iteration saved I only get the output of the last iteration. Can someone please help my with what I need to add to the code below and possibly an explanation how the whole thing should be just for future reference.
Average_smthdata = zeros(length(smthdata),40); %preallocation
for i = 1:1:70
Average_smthdata = mean([smthdata(1:end,i),smthdata(1:end,i+10)],2);
end;
Thanks! Felix
0 Kommentare
Akzeptierte Antwort
Jiro Doke
am 7 Dez. 2016
Your for loop goes from 1 to 70, so it looks like you're trying to generate 70 columns of data, not 40.
Aside from that, you would change the left hand side of your code inside the for loop to
Average_smthdata(:,i) =
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!