Understanding how to call function inside a classdef module
显示 更早的评论
I would like to understand how best to call an internal method within a classdef module. I have seen two syntaxes used, and either seems to work. (I am not great with the terminology, so please correct me if it adds clarity.)
Syntax 1:
set_messages( obj, message)
Syntax 2:
obj.set_message( message )
Mathworks says either one will work, and I have no reason not to beleive that: https://www.mathworks.com/help/matlab/matlab_oop/specifying-methods-and-functions.html
Are there advantages to either syntax? Is either preferable? Is one better if the method called is from a different class? Thanks in advance.
Here is a simple example using Syntax 1.
classdef myObj < handle
properties ( SetAccess = public )
message
end
methods
function set_message( obj, message )
obj.message = message;
end
function upper_message( obj, message )
set_message( obj, upper( message ) );
end
end
end
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Use Prebuilt MATLAB Interface to C++ Library 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!