Read a string as a input argument in a function

1 次查看(过去 30 天)
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 个评论
Sushanth Kini M
Sushanth Kini M 2018-4-17
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 2018-4-17
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.

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2018-4-17

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.

类别

Help CenterFile Exchange 中查找有关 Material Sciences 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by