finding nonzero values in 4 matrixes which have the same indices
Show older comments
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
dpb
on 30 May 2022
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.
Shabnam Dehziari
on 30 May 2022
dpb
on 30 May 2022
That's a minimal amount of data -- I'd combine it into one -- would make future coding much simpler.
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
Shabnam Dehziari
on 30 May 2022
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.
Shabnam Dehziari
on 30 May 2022
Categories
Find more on Delaunay Triangulation 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!