diff function can not be used for a timeseries variable ver 2019b

5 ビュー (過去 30 日間)
Haoyang Dong
Haoyang Dong 2021 年 12 月 1 日
回答済み: Walter Roberson 2021 年 12 月 1 日
My problem with this is with the diff() and ceil() fucntions, they both output the same error.
"undefined fucntion 'diff or ceil' for input argurment of type timeseries"
But from what I read about the diff function, it seems that timesseries inputs are fully within the capabilities of the function. So what am I doing wrong here? The script was given to me as a part of a simulations lab and the version of software used is not clear but is probably older than 2019b.

回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 12 月 1 日
That code is not expecting a timeseries object to be passed in: it is expecting a vector of times as the first parameter, and a vector of theta values as the second parameter, with optional third parameter.
diff() is not a function that is defined for timeseries objects. You can use methods() applied to a timeseries object to see that diff() is simply not a defined function for it.
If you need diff() of a timeseries collection, then you can do T(2:end)-T(1:end-1) to subtract entire timeseries ... assuming they are the same length and have times that align. The result would be a timeseries collection.
But your code does not expect the diff() to return a timeseries, so even if you were to replace diff(time) with time(2:end)-t(1:end-1) getting out a timeseries object, your code would fail. time(end)-time(1) would be a timeseries and something / that would involve trying to do matrix left divide \ with the transpose of the 3 (or more) dimensional data -- timeseries data has a 3 dimensional length equal to the number of timepoints.

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by