簡體   English   中英

如何在classdef matlab中調用函數

[英]How to call function in classdef matlab

我有一個類和一個函數,我想將函數放在一個類中,只是想在另一個類中調用整個函數,但是在調用時卻給出了一定的錯誤,是否可以在類構造函數中不調用它而調用函數? 我當前在類構造函數中調用,但其他可能的方法更有可能。 func需要五個參數,如何使該函數成為類?

當輸入參數給出obj.arg1=arg1;我也在構造函數中嘗試過obj.arg1=arg1; 我的代碼:

classdef myClass
        properties 
            node;
        end
        properties (Access=private)

        end
        methods
        function obj = myClass()

        func(obj,obj,obj,obj,obj);
        end

        function  node = func(arg1,arg2,arg3,arg4,arg5)
          %some operation
        end
end

您想為要調用的那些函數提供一個單獨的methods(Static)部分,而無需實例化類的實例。 對於static部分中的任何方法,都可以從另一個文件執行:

<some code here>
answer = myClass.myStaticMethod(args);
<rest of code here>

而對於沒有(Static)的泛型methods塊中的任何內容,您都必須實例化該類,然后針對該實例調用方法,即:

<some code here>
classInstance = myClass(constructor args)
answer = classInstance.myNonStaticMethod(args);
<rest of code here>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM