# Running a Matlab code in analyst mode Answered

Hi,

I am trying to use onscale analyst mode to design a linear array and then excite plane waves into the medium. I have a Matlab function that calculates the transmit delays that I need to apply to each element of the array. How can I run the Matlab function in my OnScale code and have the results in a variable or different variables?

Regards,

Moein.

## 3 comments

Chloe AllisonHi Moein,

You should be able to convert your MATLAB function into symb code in Analyst as we support mathematical expressions. Take a look at this example which calculates the delay values for a 2D array.

However, if you would like to use the delay values from MATLAB you can store them in a text file as variables, for example:

symb delay1 = 1e-6

symb delay2 = 2e-6

etc

Then in your flxinp file, you can read these variables in using the symb #read command and loop through these to apply them to your elements, for example:

piez

do loopK I 1 $narray 1

defn top$K

node $i1 $i2 $j1 $j2

bc top$K volt func 1 $delay$K

end$ loopK

end

I hope this helps!

Chloe

M MozaffarzadehHi Chloe,

Currently, I calculate the TX delays in matlab and then load them in OnScale code and it works fine. However, my goal is to use my model in a batch run to evaluate the effect of several variables and some of these variables are the input of my Matlab as well.

Is there any way to run a matlab code from onscale code?

Regards,

Moein.

Chloe AllisonHi Moein,

There is no way to run MATLAB code from OnScale but you can run OnScale code from MATLAB using the toolbox.

See the following articles which might be of use:

Getting Started with MATLAB Toolbox

Multi Layer Transducer Monte Carlo Study

Best Regards,

Chloe

Please sign in to leave a comment.