How can I call a function inside a class in the command window?

I'm new to matlab and I want to call a function contained inside a class in the comand window to run it. The method is not static. How can I do it? Also is there a simpler way to run the function? Also what is obj?
classdef my_class
properties
param
end
methods
function [x,y] = my_function(obj,a,b)
....
end
end
end

3 件のコメント

Tommy
Tommy 2020 年 4 月 4 日
編集済み: Tommy 2020 年 4 月 4 日
You can create an instance of my_class,
A = my_class
and then call any public methods of my_class through that instance, such as
A.my_function(a,b)
I only passed two argument into my_function because the first argument (obj) is always the instance of the class, in this case A. It is similar to 'this' in Java or 'self' in Python. You don't have to call it obj - you could define your function as
function [x,y] = my_function(this,a,b)
....
end
if you wanted.
Jay
Jay 2020 年 4 月 5 日
What if the code is like that? The input argument "value" is a .txt file.
classdef my_class
properties
prop
end
methods
function [output,value] = my_function (obj,input,value)
prop1 = obj.prop(1);
prop2 = obj.prop(2);
prop3 = obj.prop(3);
in1 = input(1);
in2 = input(2);
in3 = input(3);
end
end
end
Ameer Hamza
Ameer Hamza 2020 年 4 月 5 日
Jay, is the value name of the .txt file (a char array)? You can still call any public method of a class using the syntax described by Tommy.

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

回答 (1 件)

SaiDileep Kola
SaiDileep Kola 2020 年 4 月 9 日

0 投票

In addition to above going through this linkwould help you ramp up using classes in MATLAB.

カテゴリ

ヘルプ センター および File ExchangeTroubleshooting in MATLAB Compiler SDK についてさらに検索

質問済み:

Jay
2020 年 4 月 4 日

回答済み:

2020 年 4 月 9 日

Community Treasure Hunt

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

Start Hunting!

Translated by