How to store every iteration value

1 view (last 30 days)
Eagle
Eagle on 10 Oct 2013
Edited: Eagle on 12 Oct 2013
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.

Answers (1)

cr
cr on 10 Oct 2013
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.

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!