How to store every iteration value
조회 수: 1 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
답변 (1개)
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.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!