how to overload methods for timeseries ?

1 次查看(过去 30 天)
How to overload methods for timeseries ? I want to add some methods for timerseries objects, eg atan2(TS1,TS2), power(TS,a), sqrt(TS). The global target is to ease postprocessing of logging data from simulink (with a more 'fluid' code).
I tried to define a directory \@timeseries (in my work directory), containing the dedicated functions.
When I type >>help power, the help includes the mention 'Overloaded methods:timeseries/power'.
Nevertheless, power(TSobj,2) always rethrow the error 'Undefined function 'power' for input arguments of type 'timeseries'.

回答(1 个)

Hannes Daepp
Hannes Daepp 2017-2-14
For methods defined in separate files, the constructor still needs to be in the directory , which effectively means that you have to define the methods in the installation directory. You can find that using the following command:
>> which -all timeseries
The first result is likely the constructor, which is located in the @timeseries folder.
For example, if you create a "power" function in this directory (you may need to copy it in outside MATLAB to ensure write access), you can then use the following commands to update MATLAB:
>> rehash toolboxcache
>> clear classes
While this will work, I wouldn't necessarily recommend it. There are a few other options you might consider:
  • Use a subclass so that you do not have to change the installation directory.
  • Define new post-processing functions in your current working directory that you could use directly. While you could match the names to the built-in functions, it would be wise to name them differently to ensure that you do not observe a number of shadowing errors.
  • Alternatively, you could always store your Simulink outputs in another form, e.g. as an array.

类别

Help CenterFile Exchange 中查找有关 Search Path 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by