Read a string as a input argument in a function

조회 수: 1 (최근 30일)
Sushanth Kini M
Sushanth Kini M 2018년 4월 17일
댓글: Walter Roberson 2018년 4월 17일
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