Clear Filters
Clear Filters

Why do I need to divide by 12 in the second line to make it equal to line 1?

1 view (last 30 days)
year_avg = mean(sum(sum(sum(dl,1),2),3),4);
year_avg= mean(sum(dl(:)))/12;
  4 Comments
Basil C.
Basil C. on 4 Jul 2018
If I'm not wrong you don't need to use mean because the output of
(sum(sum(sum(dl,1),2),3),4) and
sum(dl(:))
is a single number and not a vector.
Nesha Wright
Nesha Wright on 4 Jul 2018
If I remove the mean, I get a 4-D single array, however, I am still not sure what the difference between my first two lines in the original question is (regarding the 12).

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 4 Jul 2018
dl is a 4-D array. Think of it as a 3-D volumetric chunk of data, and there are 12 of them, like 12 blocks.
Now, what exactly do you want to do with those 12 blocks?
Average each block so that you have 12 averages - an average over all elements in each block?
Or an average over all possible elements over all 12 blocks so that you have only one average? If so, try this:
year_avg = mean(dl(:));
  7 Comments
Nesha Wright
Nesha Wright on 5 Jul 2018
The file is too large to attach, it is monthly emissions data for multiple years, dimensions are lat, long, sector (where the emissions are from) and time (monthly). Because the time is monthly that is why in line 2 I divide by 12 however I am not sure why I don't need to do so in line 1.
Image Analyst
Image Analyst on 6 Jul 2018
And you can't read it in and save just a few years worth of data in a new .mat file??? OK, whatever. Failing having some data to work with all I can say is that the code should work.

Sign in to comment.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!