Filling gaps in a vector using a secondary data set

조회 수: 2 (최근 30일)
Lejla Latifovic
Lejla Latifovic 2022년 8월 3일
댓글: Les Beckham 2022년 8월 3일
Hello,
I have two half-hourly precipitation datasets for 2021 (rain gauge 1 and rain gauge 2).
Rain gauge 1 has NaN values at the start and end of the year. For these two time periods I would like to replace the NaN values with data from the rain gauge 2 dataset.
Is there a good way to do this? Do I need to pull out the values I would like to use from each vector and then join them together into a new vector? This seems clunky?
Thank you!

채택된 답변

Les Beckham
Les Beckham 2022년 8월 3일
편집: Les Beckham 2022년 8월 3일
rain1 = [nan nan 1:10 nan nan] % example data
rain1 = 1×14
NaN NaN 1 2 3 4 5 6 7 8 9 10 NaN NaN
rain2 = [20:34]
rain2 = 1×15
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
idx = isnan(rain1); % find where rain1 has nans
rain1(idx) = rain2(idx) % replace them with data from rain2
rain1 = 1×14
20 21 1 2 3 4 5 6 7 8 9 10 32 33
  댓글 수: 2
Lejla Latifovic
Lejla Latifovic 2022년 8월 3일
This is great, thank you!
Les Beckham
Les Beckham 2022년 8월 3일
You are quite welcome.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by