Hi. I have probability p in the code, so everytime I run it, different ans and elapsed time are obtained. I want to run the code for 100 times and get the avg ans and elapsed time. Do you know how to get these?

1 件のコメント

David Barry
David Barry 2016 年 12 月 22 日
No idea what you are asking. Please upload the code so we can assist further.

サインインしてコメントする。

 採用された回答

KSSV
KSSV 2016 年 12 月 23 日
編集済み: KSSV 2016 年 12 月 23 日

0 投票

clc; clear all;
N = 100 ; % number of time you run the code
elapsed_time = zeros(N,1) ; % initilaize the elapsed times
result = zeros(N,1) ; % initilaize the result for every run
for i = 1:N % loop for each run
t = tic ; % to get time evaluated
% do waht you want
K = rand(i) ;
thenorm = norm(K) ;
t = toc(t) ; % get time elapsed
result(i) = thenorm ; % store your result for final average
elapsed_time(i) = t ; % store the time elapsed for the run
end
% get avarages
result_avg = mean(result) ;
time_avg = mean(elapsed_time) ;
I have calculated the norm of a random matrix here, in place of that you call your probability code.

1 件のコメント

tingting
tingting 2016 年 12 月 27 日
It works! Thank you :)

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 12 月 23 日

0 投票

If you are interested in measuring average performance of your routine (rather than being interested in the average time to produce that specific set of values), then see timeit()

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

質問済み:

2016 年 12 月 22 日

コメント済み:

2016 年 12 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by