Include compose functions

Matthieu Pupat
Matthieu Pupat
Altair Employee
edited August 2021 in Community Q&A

Hello,

 

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

 

Thanks,

 

Matthieu

Tagged:

Welcome!

It looks like you're new here. Sign in or register to get started.

Answers

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited April 2018

    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)

  • Matthieu Pupat
    Matthieu Pupat
    Altair Employee
    edited May 2018

    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

  • manoj kandukuri
    manoj kandukuri
    Altair Employee
    edited February 2021

    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

  • Dario Mangoni_21783
    Dario Mangoni_21783
    Altair Employee
    edited August 2021

    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.

     

Welcome!

It looks like you're new here. Sign in or register to get started.

Welcome!

It looks like you're new here. Sign in or register to get started.