🎉Community Raffle - Win $25

An exclusive raffle opportunity for active members like you! Complete your profile, answer questions and get your first accepted badge to enter the raffle.
Join and Win

Include compose functions

User: "Matthieu Pupat"
Altair Employee
Updated by Matthieu Pupat

Hello,

 

If I define a function in an OML file, how can I call that function from another OML file?

 

Thanks,

 

Matthieu

Find more posts tagged with

Sort by:
1 - 4 of 41
    User: "Altair Forum User"
    Altair Employee
    Updated by Altair Forum User

    Hello Matthieu,

               You can call the function using function name along with input arguments.

     

    I have the following function (test) which does the addition of two input numbers.

     

    function out = test(a,b)

     out = a+b;

    end

     

    Way of calling the function:

    test(1,3)

    out = test(1,3)

    User: "Matthieu Pupat"
    Altair Employee
    OP
    Updated by Matthieu Pupat

    Hi,

     

    This works if both are in the same file. I was referring to the function being in one file and the call in a different one. How can I include the first file in the second one?

     

    Thanks,

     

    Matthieu

    User: "manoj kandukuri"
    Altair Employee
    Updated by manoj kandukuri

    Hi Matthieu,

    1st we need to save the function script with the same name and use the function name in a different file.

     

    say for example

    script 1: save the test function as test.oml

    function out = test(a,b)

     out = a+b;

    end

     

    then,

    you can call the 'test' in a different file as a script/function:

    function val = test2()

    a = 5

    b =6

    out = test(a,b)

    val = out;

    end

     

    hope this helps.

     

    Thanks,

    Manoj kandukuri

    User: "Dario Mangoni_21783"
    Altair Employee
    Updated by Dario Mangoni_21783

    Please mind that the file should be either:

    • added to 'path' by calling addpath('<pathtotestoml>); however this will affect only the current Compose session (closing and reopening Compose will reset path to its original value)
    • reside in the same folder of the calling function.

    Otherwise the test function that you saved in test.oml won't be found.