Read a string as a input argument in a function

1 view (last 30 days)
I have a function that calculates quality factors Q = Q(Thickness, Freq, etc). I also have several functions that define material constants(density, epsilon,etc) of different materials as global. I want to integrate the material constant function into my quality factor function.
Eg : I have a function SiN.m which has no input arguments and only defines the material constants for silicon nitride as global. I want a efficient way to call this function in the quality factor function. Q = Q(Thickness, Freq, SiN)
If I do this i get the error "Output argument "SiN" (and maybe others) not assigned during call to "SiN" ".
What would be the best way to achieve this?
Thank you.
  3 Comments
Sushanth Kini M
Sushanth Kini M on 17 Apr 2018
That is what I am doing now. But as more materials are added, I would have to edit the function everytime to compare strings and call the appropriate function.
Hence, looking for a more efficient solution.
Walter Roberson
Walter Roberson on 17 Apr 2018
If you make a structure or properties that you pass around, or if you make a materials properties class and pass the objects around, then you do not need to change your Q function each time a new material is added.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 17 Apr 2018

You coded as something like

function SiN = SiN

Using the same output name as function name. Then you did not assign a value to the output variable.

You are calling in a context that demands an output value.

We would recommend that you do not use global variables. It would perhaps make sense in your case for SiN to return a structure of information, or it might make sense to create a class of material properties that could be accessed.

Categories

Find more on Material Sciences in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!