필터 지우기
필터 지우기

How to define a variable of datetime datatype, having null value?

조회 수: 22 (최근 30일)
bushra raza
bushra raza 2018년 11월 15일
댓글: Steven Lord 2018년 11월 15일
I am working on water level timeseries in a project. For this I have to compare water level with a threshold value and corresponding date of the respective water level is to be recorded in a datetime variable. If the water level value is not greater than the threshold value, then corresponding date variable must be null or empty. Please guide any suggestion?
Here is my sample code:
highObservations_date = datetime; %this variable has current datetime, it must be initialized with % a null value
highObservations_value = 0;
highLevelCounter = 0;
% set threshold to be considered as High water level
threshold_High_waterlevel = double(median( BreedingSeason_waterlevels.timmendorf_water(:,1)));
for i= 1:size(BreedingSeason_waterlevels,1)
if( BreedingSeason_waterlevels.timmendorf_water(i,1) >threshold_High_waterlevel )
highLevelCounter = highLevelCounter + 1;
highObservations_date = BreedingSeason_waterlevels.timmendorf_time(i,1);
highObservations_value = BreedingSeason_waterlevels.timmendorf_water(i,1);
end % end of if
if (highLevelCounter >1)
break;
end % end of if
end % end of for loop

채택된 답변

Steven Lord
Steven Lord 2018년 11월 15일
The standard missing value for a datetime array is NaT.
  댓글 수: 2
bushra raza
bushra raza 2018년 11월 15일
thanx , it worked . but now i have another query regarding this NaT.
i want to check if a datetime variable is not null,then do a list of code , but although my variable is having NaT value,even then the inner code runs.. i put it like this :
if(highObservations_date ~= NaT )
Lost = Lost +1; %increment Lost by 1
end %end of if
Steven Lord
Steven Lord 2018년 11월 15일
NaT is not equal to any other datetime, not even another NaT. Use the isnat function to detect NaT values in your datetime array just like you would use isnan to detect NaN values in a double array.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by