Using obj within function without passing it
古いコメントを表示
I have a number of class methods that use self (or obj) within the code. The online documentation indicates I do not need to pass obj to the function to use it within, but my code does not work without passing it.
For clarity in case it is an issue - my class is a derived class of type < handle. Using Matlab 2016b
What I would like is this (with or without returning obj):
function obj = Update2(time)
obj.LastUpdate = time;
end
but creates a new obj instead of using the calling obj (which is a handle to the obj of class that includes the function). The code I end up with (works fine) is below, but it means calling it with MyObject.Update(MyObject, time)... seems kind of wrong/unnecessary.
function Update(obj, time)
obj.LastUpdate = time;
end
My calling functions are below - top one works, bottom does not as it returns a new obj.LastUpdate, not the 'h.' calling obj.LastUpdate.
Pretty sure this can be done... what am I missing...?
h.Update(h,111) % Works
h.Update2(222) % INOP
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Properties についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!