Standard Deviation for X,Y data over 30 Years

4 vues (au cours des 30 derniers jours)
John Cruce
John Cruce le 2 Juil 2023
Modifié(e) : dpb le 2 Juil 2023
I have 30 years of monthly average temperature for global latitude/longitude in a matrix A (dimensions Y,X,Year; size 361,721,30). I want to compute the standard deviation for each lat/long over the 30-year period so the resulting matrix should be size (361,721).
I've tried std(A,[],3) but the standard deviation isn't correct. Any thoughts on what I'm doing wrong or how to do this using the STD function?
  2 commentaires
dpb
dpb le 2 Juil 2023
What makes you think the result of std is in error? I've never had it fail...sometimes there are ~isfinite() values or other bogus data that can fool you, but that's not the fault of std
Attach enough to show us what isn't what you think it should be; the obvious way would be to attach the .mat file of your data...
dpb
dpb le 2 Juil 2023
Modifié(e) : dpb le 2 Juil 2023
A=randi(100,5,5,5);
S1=std(A,[],3)
S1 = 5×5
29.5888 36.7056 33.7831 27.3807 29.1153 34.1980 26.2145 24.1661 37.8061 17.2279 26.7526 36.8673 32.9424 41.0122 32.5346 16.1864 25.1734 17.5926 36.8578 15.4272 19.0342 23.5266 16.1245 20.5353 21.6102
S2=std(A,0,3)
S2 = 5×5
29.5888 36.7056 33.7831 27.3807 29.1153 34.1980 26.2145 24.1661 37.8061 17.2279 26.7526 36.8673 32.9424 41.0122 32.5346 16.1864 25.1734 17.5926 36.8578 15.4272 19.0342 23.5266 16.1245 20.5353 21.6102
std(A(1,1,:))
ans = 29.5888
v=squeeze([A(1,1,:)]);v=v-mean(v);
sqrt(dot(v,v)/(numel(v)-1))
ans = 29.5888
sqrt(v.'*v/(numel(v)-1))
ans = 29.5888
Shows it all seems to work as expected. I noticed the doc stated to use the 0 weight argumet explicitly so just checking that [] did as expected (sure it would) as well...

Connectez-vous pour commenter.

Réponses (1)

the cyclist
the cyclist le 2 Juil 2023
I agree with @dpb's comment. The only other thing I can think of is that the syntax
std(A,[],3)
which seems to be equivalent to
std(A,0,3)
gives you normalization by N-1, which would typically what you want for sampled data. If instead you wanted normalization by N (typically for population data), then you can do
std(A,1,3)
instead. But I expect that is not the issue you mean.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by