How do you get a global average at each time step so they can be summed?

3 ビュー (過去 30 日間)
Nesha Wright
Nesha Wright 2018 年 6 月 23 日
回答済み: Ameer Hamza 2018 年 6 月 25 日
I have a 4D array of emissions. I want the average emissions at each time step so that I can then sum all of these averages and determine the total emissions by a certain year (in this case the entire file).
I think that I need to use a loop but am not sure how. I am currently using this: mean_time=sum(squeeze(mean(mean(mean(total,1),2),3))); as time is the 4th dimension.
  2 件のコメント
Ameer Hamza
Ameer Hamza 2018 年 6 月 23 日
What do you think is wrong with this, it is better to use vectorized code instead of using for loop. Also the above is equivalent to
mean_time = sum(mean(mean(mean(total))));
Nesha Wright
Nesha Wright 2018 年 6 月 25 日
The only problem I was seeing was that I couldn't get a specific time from this which I think is just throwing my logic off. For example, if I wanted timestep 5 rather than the sum of the entire thing.

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

採用された回答

Ameer Hamza
Ameer Hamza 2018 年 6 月 25 日
If you want to average at each time step as by omitting the sum() function. For example
averageTimeSteps = mean(mean(mean(total)));
if total is a 4D matrix, the above command will produce a 1D vector. You can access element just as a regular vector e.g. averageTimeSteps(1), averageTimeSteps(2), ... etc. However, the result is still a 4D matrix so display might be a bit confusing. To simplify the display, try
averageTimeSteps = squeeze(mean(mean(mean(total))));

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by