finding nonzero values in 4 matrixes which have the same indices

I have 4 matrixes ( 4 decade's ozone data in 19.5 km altitude which its missing values are replaced by 0.0.). I want to compute area-weighted mean by taking values only from grid cells where ozone data are available for all four decades. How I should get these grid cell values? I have tried the following but after using this cells values, the result is wrong ( i am sure the weights are compeletly correct.so the problem is related to my ozone data).
b=find(ozone70>0 & ozone80>0 & ozone90>0 & ozone2000>0);
o70= ozone70(b); % getting the ozone value in 70's decade from cells which are nonzero in other 3 decades

3 Comments

How much data are we talking about here? I'd be for building a 3D array where the 3rd plane is time instead of messing around with multiple variables as above.
That (numbering variables with a sequence number) is virtually always a sign of a poorly chosen data structure in MATLAB, causing all sorts of coding grief such as this.
each matrix includes ozone data over globe in (5*5 latitude and longtitude grid cells) in 19.5 km above Earth surface ( which include 36*72=2592 ozone value). I have 4 matrix for 1970's,1980's, 1990's and 2000's)
That's a minimal amount of data -- I'd combine it into one -- would make future coding much simpler.

Sign in to comment.

Answers (1)

b=(ozone70>0 & ozone80>0 & ozone90>0 & ozone2000>0);
areas=Areas(b);
o70= ozone70(b);
weightedMean=dot(areas/sum(areas),o70)

3 Comments

Thank you, I test your code,as well. I get the result which i have got with mine which is different with the result my supervisor has published in her paper!
Perhaps she made an error...
It's easy to verify that we're doing the calculation correctly. Just make some test data where the ozoneXX variables are small 3x3 matrices or something. Then, it's easy to check the calculation against a by-hand calculation.

Sign in to comment.

Categories

Asked:

on 30 May 2022

Edited:

on 31 May 2022

Community Treasure Hunt

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

Start Hunting!