Use variables in equation


d = 50 - ((pir^2) / (r^2pi + p^2))*T;

I want to define d as a function of r and T

r and T are variables and p is constant

Then how can I write this in the script?
How can I use num2str( ) in this equation?


Hi @nykim11

Thank you for your post.

If r and T are just two scalar variables, you could put them as they are in the equation. If r and T are two arrays and you want the result d to be a 2D matrix, there are 2 ways to do so. In one way you could pre-define the matrix d with the size [length®, length(T)] and use for loops to calculate for each element of d. In another way, you could “meshgrid” r and T to matrices by using meshgridx and meshgridy commands and then use the new r and T to calculate for d. The example file use_variable_in_equation.lsf (187 Bytes) could be used as a start point.

For the num2str command, I don’t think you need to use it in defining the equation, but if you want to write the result d to a text file, you could use it together with the write command.

I hope this could help :slightly_smiling: