add data to an existing object with a method not in @ directory

2 ビュー (過去 30 日間)
Roy Goodman
Roy Goodman 2019 年 2 月 14 日
コメント済み: Adam 2019 年 2 月 14 日
I have created a class of objects, and have stored the core methods for working with these objects in a directory whose name starts with @.
Now I'd like to write another method to modify my object, but it's not core to the functioning of the class, so I don't want to put it in the @ directory because it's not general purpose enough.
If x is the name of the object, I would like to modify it in place by a call to
x.myFunction(arguments)
but the only way I know how to do this without putting myFunction into the @ directory would be to write the code as
x = myfunction(x, arguments)
but this would be bad for what I think are obvious reasons.
  3 件のコメント
Walter Roberson
Walter Roberson 2019 年 2 月 14 日
modifications in place are restricted to classes derived from handle, which your class does not appear to be .
Adam
Adam 2019 年 2 月 14 日
Either the function belongs on the class or it doesn't. If it does it needs to either be defined in the class file or in the @ directory (I never use the latter method, I always define all class functions in the class file itself, but I assume that is the case). If it doesn't then it can be anywhere but would just work with the class object and its public functions/properties like any other external function.

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeConstruct and Work with Object Arrays についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by