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 个评论
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
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!