Using normpdf with datetime datatype

조회 수: 5 (최근 30일)
Pankaj
Pankaj 2019년 8월 21일
답변: Mahesh Taparia 2019년 8월 26일
I have a vector of time in datetime datatype. I would like to calculate the Normal pdf by giving arguments in datetime datype. normpdf does not work with datetime arguments, but it works if I convert the arguments to datenum
Non-scalar arguments must match in size.
Consider the following-
today = datenum('21-Aug-2019');
xs = datestr((today-5):(today+5));
x = datetime(xs);
mu = datetime(datestr(today));
stdev = hours(20);
The following does not work-
weight = normpdf(x, mu, stdev)
but the following works-
weight = normpdf(datenum(x), datenum(mu), datenum(stdev))
Just want to check, if it is possible to make normpdf with datetime.

채택된 답변

Mahesh Taparia
Mahesh Taparia 2019년 8월 26일
Hi,
It is not possible to use normpdf with the input in datetime format (which is not in scalar format). This command requires scalar values/ array of scalar values as input. You are getting result with the 1st command because datenum converts the date into number and it is equal to the number of days from January 0, 0000.
For more information on normpdf, you can refer the below link:

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by