problem with if cycle to determine the datetime
古いコメントを表示
hi, i'm using a function to retrieve weather data with API. I divided the function in two section, one where the outputs is the current weather and one for "past" weather. To decide which output the function has to print I made a simpole if cycle:
if fullDate == now
... %outputs current weather
else
... %outputs historic weather
end
if I try to run the single part everything works perfecty, but adding this if cylce I get this error message using fullDate = now;
Numeric input data must be a matrix with three or six columns, or else three, six, or seven separate numeric arrays. You can also create datetimes from a single numeric array using the 'ConvertFrom' parameter.
the wierd thing is that if I continue to run the code (without touching it) after a few errors sometimes it runs without any problem.
I don't get where is the problem... thanks
2 件のコメント
Luca Tognetti
2023 年 2 月 3 日
datetime('now') returns the current date and time, so in general it returns a different thing each time you call it, because of the passage of time.
fullDate = datetime('now')
pause(0.5)
fullDate = datetime('now')
In other words, what 'now' means changes with time, as it should.
I don't have enough information about your code or what you're trying to do to advise you about what you should do instead.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Weather and Atmospheric Science についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!