How to calculate the average value of energy samples obtained from simulation

11 ビュー (過去 30 日間)
Roberto
Roberto 2013 年 10 月 1 日
回答済み: Roberto 2013 年 10 月 1 日
At the end of simulation a vector of size tmax (residual_energy) is generated: it contains all the values of residual energy at t varies from 1 to tmax. This is the vector I'd like to plot. I would like to carry out the simulation 20 times and then use the average of the results. This is the solution I thought:
%create the energy matrix (sim_number X tmax): each row represents the residual_energy vector
for trial = 1:sim_number
run simulation;
energy(trial,:) = residual_energy;
end
%I get the final vector by averaging column by column
for t = 1:tmax
average_residual_energy = mean(energy(:,t));
end
plot(average_residual_energy);
Is this method to obtain the average value correct? Please help, this is my first simulation!

回答 (2 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 10 月 1 日
You do not need a for loop
average_residual_energy = mean(energy)

Roberto
Roberto 2013 年 10 月 1 日
Ok, i don't need a loop. But I want to know if the method is right! I mean, the average value of energy at time t1 is the average of all values of energy at t1 in every simulation?

カテゴリ

Help Center および File ExchangeThermal Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by