function command hellp
古いコメントを表示
I have a function file have code like this
--------------------------------------------
function GH = Gibbs(R,T,Z,A,B)
% Calculate the Enthalpy, Enropy, Gibbs free energy
GH = R*T*((Z-1)- log(Z-B)- A/B*log(Z+B/Z));
end
------------------------------------------
I have values of R, T, Z, A, B in another m-file , how I compute this by calling the other file for the values of R,T,Z,A,B
回答 (2 件)
Honglei Chen
2012 年 2 月 14 日
Let's say the other file is foo.m, then you can modify the signature of foo to return those values, e.g.
function [...,R,T,Z,A,B] = foo(...)
Then you can call them in sequence like this:
[...,R,T,Z,A,B] = foo(...);
GH = Gibbs(R,T,Z,A,B);
5 件のコメント
Nasir Qazi
2012 年 2 月 14 日
Honglei Chen
2012 年 2 月 14 日
Those are whatever the original inputs and outputs are. If you don't have inputs and outputs, then it will reads like [R,T,Z,A,B] = foo
Nasir Qazi
2012 年 2 月 14 日
Nasir Qazi
2012 年 2 月 14 日
Honglei Chen
2012 年 2 月 14 日
I'm starting a new answer
Honglei Chen
2012 年 2 月 14 日
Then I will rewrite the other file into a function, using signatures like
function [T,Z,A,B] = foo(R)
Once you do that, you can call them in order
[T,Z,A,B] = foo(R)
GH = Gibbs(R,T,Z,A,B)
13 件のコメント
Nasir Qazi
2012 年 2 月 14 日
Nasir Qazi
2012 年 2 月 14 日
Nasir Qazi
2012 年 2 月 14 日
Nasir Qazi
2012 年 2 月 14 日
Nasir Qazi
2012 年 2 月 14 日
Honglei Chen
2012 年 2 月 14 日
It looks like you want to calculate GH for each iteration? If that's the case, you need to break your first file into two. One of them just supply T,Z,A,B from R and the other one runs the loop. Then you can have a similar one to do a loop and calculate GH.
Nasir Qazi
2012 年 2 月 14 日
Honglei Chen
2012 年 2 月 14 日
You have to use a function to transfer these values out of the first file. Did you ever try making the first file like
function [R,T,Z,A,B] = foo
R=1;
T=20;
Z=4;
A=3;
B=1;
Nasir Qazi
2012 年 2 月 14 日
Honglei Chen
2012 年 2 月 14 日
That's your function. Then in the command line, do
[R,T,Z,A,B] = foo
and you should get those values
Nasir Qazi
2012 年 2 月 14 日
Honglei Chen
2012 年 2 月 14 日
Then you can call it within the other file
function GH = Gibbs
% Calculate the Enthalpy, Enropy, Gibbs free energy
[R,T,A,Z,B] = foo;
GH = R*T*((Z-1)- log(Z-B)- A/B*log(Z+B/Z));
end
Nasir Qazi
2012 年 2 月 14 日
カテゴリ
ヘルプ センター および File Exchange で NaNs についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!