Class implementation such that assignment x=MyObj does in fact x=MyObj.prop1
Mostra commenti meno recenti
Let's say I have a class
classdef TestClass < handle
properties
prop1 = 7
prop2
end
methods
function method1(obj)
fprintf('prop1 is %g.', obj.prop1);
end
end
end
Now, when I do
Obj = TestClass;
x = Obj;
I want that the value of property prop1 is assigned to x, instead of the reference to Obj. So this assignment results to x=7.
And I would prefer to keep the class to be inherited from handle. But value class will also do.
I still would like to access prop2 as Obj.prop2 and call all the methods.
How this can be implemented in a custom class?
Thanks!
2 Commenti
Matt J
il 4 Ago 2022
The similar behaviour the MATLAB's class string has.
I don't think so. You should probably demonstrate what you mean.
Oleg Iupikov
il 4 Ago 2022
Modificato: Oleg Iupikov
il 4 Ago 2022
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Class Introspection and Metadata in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!