フィルターのクリア

Mean of the third dimension

48 ビュー (過去 30 日間)
desert_scientist90
desert_scientist90 2019 年 10 月 23 日
コメント済み: John D'Errico 2019 年 10 月 24 日
Hi I an new to matlab and learning thru practice and patience. I have a data set with for precipitation containing data for 37 years. X=141, Y=41 and T=37. I want to get the mean per year (37) I tried the following code but on my dataset I ended uo with 71 observations. Why this is happening? If I only want the mean per year? Thanks in advance.
avg3=nanmean(rain(:,:,3));

採用された回答

John D'Errico
John D'Errico 2019 年 10 月 23 日
編集済み: John D'Errico 2019 年 10 月 23 日
Not entirely sure what you are asking.
Do you want to compute the mean for each year for each combination of X and Y? That would result in a 141x41 array.
MeanRain = mean(rain,3);
Do you want to compute the mean over all X and Y, resulting in one element per year, so a vector of length 37? Here, I'd just reshape the rain matrix to be a 141*41 by 37 array, so 2-dimensional. Then take the mean down the columns of that array, so on the first dimension. The result of the computation below would be a 1x37 vector.
MeanRain = mean(reshape(rain,[],37),1);
Either could be what you are asking.
  2 件のコメント
desert_scientist90
desert_scientist90 2019 年 10 月 23 日

Sorry if I was not clear enough. My goal is to achieve one mean ( point) per year. In total I want 37 averages one per year. After that I want to calculate the zscore per year to be able to do a time series.

John D'Errico
John D'Errico 2019 年 10 月 24 日
Then you just use the second option I gave.

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

その他の回答 (1 件)

TADA
TADA 2019 年 10 月 23 日
編集済み: TADA 2019 年 10 月 23 日
try this:
avgPerYear = nanmean(rain, [1,2]);
that would generate an inconvenient 3rd dimention vector
so you can reshape it into a row\column vector:
avgPerYear = reshape(nanmean(rain, [1,2]), size(rain,3), 1, 1); % column vector output
avgPerYear = reshape(nanmean(rain, [1,2]), 1, size(rain,3), 1); % row vector output

カテゴリ

Help Center および File ExchangeTime Series についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by