Why is day() function throwing me this error: Check for missing argument or incorrect argument data type in call to function 'day'?

Having this task:
Perform a regression model over the normalized active cases in China using the model.....(long assignment that I'm not worried about). Tip: To convert from datetime to a numeric variable for the regression, use x=day(date-min(date(:)))+1; being “date” the datetime vector return from getdata function.
This is what I have until now:
function RP_ejercicio1
data = readtable('COVID-19.csv');
[active_res, confirmed_res, death_res, recovered_res, date] = getdata(data, 'China', 93/147);
x=day(date-min(date(:)))+1;
y = active_res;
yp = log(y./x);
a = [x ones(size(x))];
sol = inv(a'*a)*(a'*yp);
b = sol(1);
c = sol(2);
a = exp(c);
end
I'm getting an error in this line
x=day(date-min(date(:)))+1;
and I don't get it. From getdata function I'm getting successfully a 1x50 datetime array fulled with dates and stored in my date variable. What am I doing wrong?

1 件のコメント

Shalini K
Shalini K 2020 年 5 月 11 日
letterds = datastore("*_M_*.txt"); data = read(letterds); data = scale(data); plot(data.X,data.Y) axis equal plot(data.Time,data.Y) ylabel("Vertical position") xlabel("Time")

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

 採用された回答

Cris LaPierre
Cris LaPierre 2020 年 3 月 27 日
編集済み: Cris LaPierre 2020 年 3 月 27 日
Based on the arithmetic you are doing with your date, I think you want to use the function days instead of day. The former returns the number of elapsed days as a duration, which is typically what you want when you subtract two dates. The later extracts the day number from a date, as in day of the month.
x=days(date-min(date(:)))+1;

2 件のコメント

You can't imagine how much I owe you, I was just giving up. You are right, it's a mistake in the task. I can finally keep with my work after hours of frustration.
Again, thank you very much.
I only know because I've made the mistake myself. Glad to have helped.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Time Series Objects についてさらに検索

製品

リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by