How to store every iteration value

1 次查看(过去 30 天)
Eagle
Eagle 2013-10-10
编辑: Eagle 2013-10-12
I need to run the code for iteration=20000 times and i need to store the value of "D" for every trial.I run this code only one time,But if i want to run this code for 20000 time then how can store every iteration value.I need to store only "D" value.
Matlab experts need your help and suggestion.

回答(1 个)

cr
cr 2013-10-10
1. You dont have to write a loop to get difference values. Just do diff(D). Or, before you do rec2_Wopt(1) = rec2_Wopt(1) + sum(RecP), create a D2(count,:) = rec2_Wopt(1)/Trial (not sure if I understood what you are doing, so check it. The point is, just save the D vector before you do a cumulative sum inside the loop).
2.You will have to wrap the entire code inside another loop and need to create a 3-dimensional matrix for D, where, in the third dimension you will store the D matrix at every iteration. Then, you will be doing D(count,:,iter) = ... where iter runs from 1:20000
Preallocate memory for D if you use such big loops. Also check if loops are avoidable and if you can do it by vector ops.

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by