How to call the function?

1 次查看(过去 30 天)
Hey all,
I have two function file and one slover file. One function file for Input and another for some calculation. Here, all these files are interdependent.
For an example:
This is the user input file:
function [n,Lambda, A, B, D,H,V, Rho,cP] = Matrix_Samplemodel(Node_num, Conductivity,contact_area,Width, Diameter, Height,Volume, Density,Heat_Capacity)
% From the user input output Matrix will be built.
end
second one is conductance file
function LA = Conductance
[n,Lambda, A, B, D,H,V, Rho,cP] = Matrix_Samplemodel(Node_num, Conductivity,contact_area,Width, Diameter, Height,Volume, Density,Heat_Capacity);
% some calculation to get LA by using the output arguments of first user input file.
end
This file has to take the value from the first inuput file. But user will enter the input values in the slover file:
This is the solver file:
function SampleModel_Stat
%[n,Lambda, A, B, D,V, Rho,cP,P] = Matrix_Samplemodel(Node_num,Conductivity, contact_area,Width, Diameter,Height, Volume, Density,Heat_Capacity)
[n,Lambda, A, B, D,H,V, Rho,cP] = Matrix_Samplemodel(10, 205 , 4749.50 ,25, 55,0, 2.3746e+05 , 7760,431);
%In the solver user is giving the Input values.
LA = Conductance;
end
Now all these three are different filles.
When I run the solver it is showing erorr like below.
SampleModel_Stat
Undefined function or variable 'Node_num'.
Error in Conductance (line 3)
[n,Lambda, A, B, D,H,V, Rho,cP] = Matrix_Samplemodel(Node_num,Conductivity, contact_area,Width,
Diameter,Height, Volume, Density,Heat_Capacity);
Error in SampleModel_Stat (line 19)
LA = Conductance;
Here How can I call the output of the user input function in the second file(Conductane file) to get the LA in the solver file. But user will enter the input arguments in the Solver file, not in user input file or in conductance file.
Any suggestions and answered are most welcomed.
Thanks in advance
  2 个评论
Stephen23
Stephen23 2019-7-5
编辑:Stephen23 2019-7-5
As the error message clearly states, inside the function Conductance the variable Node_num is undefined (and also Conductivity, contact_area, Width, Diameter, Height, Volume, Density, and Heat_Capacity).
In MATLAB variables must be explicitly passed from one workspace to another, they do not just jump magically from another workspace where they might exist. If you want to use variables from another workspace inside Conductance, then you will need to pass them as input arguments or use nested functions.

请先登录,再进行评论。

回答(0 个)

类别

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

产品


版本

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by