Replace some values to NaN using a condition found in a second vector

조회 수: 6 (최근 30일)
Hello everyone!
I am trying to clean a time series and I am having some trouble.
I have a variable DOY, which contains the day of the year and a variable H, which contains the data I am trying to clean. They are both 1200x1 in size.
Example: Between the days 321 and 330, I want every H>30 to be replaced with NaN. I don't want to simply create new variables because I have lots of conditions like this one to apply to the data.
I tried solutions like:
idx = find(DOY>=321 & DOY<=330);
if H(idx)>30
H(idx) = NaN;
end
In this one, nothing happened; Then, I tried multiple versions with a while loop, and the last one was that:
while true
idx = H<=9.6;
H(idx) = NaN;
if ~find(DOY>=330 && DOY<=336.3)
break
end
end
In all my while loops I get the same error "Operands to the || and && operators must be convertible to logical scalar values."
I wrote in different ways and still can fix this.
Thank you in advance for any tips you can give me!

채택된 답변

Thaís Lobato Sarmento
Thaís Lobato Sarmento 2022년 3월 24일
I think I got it! I put all the conditions in a single find!

추가 답변 (1개)

KSSV
KSSV 2022년 3월 24일
idx = DOY >= 321 & DOY <= 330 ;
H(idx) = NaN ;
  댓글 수: 1
Thaís Lobato Sarmento
Thaís Lobato Sarmento 2022년 3월 24일
Unfortunately this doens't solve my problem..
What I need is, between DOY 321 and 330, to put NaN only on those places where H>30

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

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by