Detrending a time series with NaN values

14 ビュー (過去 30 日間)
Brian DeCicco
Brian DeCicco 2021 年 6 月 18 日
コメント済み: Brian DeCicco 2021 年 6 月 21 日
Hello, I am attempting to detrend a time series of dimensions 97x97x117 (double) that contains sea surface temperature data at various longitude and latitude points. The data is represented by NaN values over landl, as expected. When I take the mean of the above matrix across the 3rd dimension and plot it, the data all shows up just fine over the water. However, if I detrend the above matrix and then take the mean across the 3rd dimension, and then plot it, the data cuts off around 39 degress north (where land/NaN values start creeping in), so I know the issue resides with method I'm using to detrend. See image attached. Originally I used the detrend(x) method, however there is reference to the following modification of the code from another Mathworks user, as this seems to be a known issue with NaNs in data:
When I attempt to use this modification, I get the following error:
Undefined function 'detrendNaN3' for input arguments of type 'double'.
Error in SST (line 24)
SST_all_events_detrend = detrendNaN3(yearly_array2); %array of size 97x97x117
Here is a snip-it of the code that I am using:
SST_all_events_detrend = detrendNaN3(yearly_array2); %detrend time series of dimensions 97x97x117
SST_all_events_mean = mean(SST_all_events_detrend,3); %mean across all events
I appreciate any assistance that you may be able to provide!

採用された回答

dpb
dpb 2021 年 6 月 19 日
With recent (but I'm not sure just how recent) releases, there's the 'omitnan' optional parameter in detrend that will skip the nan elements and operate on the rest.
  1 件のコメント
Brian DeCicco
Brian DeCicco 2021 年 6 月 21 日
Thank you, that worked! I had forgotten about that very useful parameter for this case :)

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by