how to use result of one function for another function??

i want to use the results of one function for another function within the same or different file...plese help me how to do it....
sample program:
function [ y ] = heatsource( x1, x2 )
function [ x1, x2] = result( c, d )
c=2;
d=3;
x1=c+d;
x2=c-d;
end
y=x1+x2;
y
end

 채택된 답변

Chandrasekhar
Chandrasekhar 2014년 4월 28일
mainscript.m
c=2; d=3;
[ x1, x2] = result( c, d )
[ y ] = heatsource( x1, x2 )
result.m
function [ x1, x2] = result( c, d )
x1=c+d;
x2=c-d;
heatsource.m
function [ y ] = heatsource( x1, x2 )
y=x1+x2;

댓글 수: 3

thanks for giving time to my problem and providing suitable solution... i want to know that is that method possible if i write the algorithm in diffrenet script files in form of functions.......then will it work if i call all the fuctions(5 functions created) in a seprate script file.
for example.....create result.m and hetasource.m in different script files. and call them in mainscript.m
exactly.
Should result.m and heatsource.m be in the same folder so heatsource.m can read x1 and x2?

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Andrei Bobrov
Andrei Bobrov 2014년 4월 29일
function [ y ] = heatsource( c,d )
function [ x1, x2] = result( c, d )
x1=c+d;
x2=c-d;
end
[ x1, x2] = result( c, d );
y=x1+x2;
end
Azzi Abdelmalek
Azzi Abdelmalek 2014년 4월 28일
Save this function as heatsource.m
function [ y ] = heatsource( c,d )
[ x1, x2] = result( c, d )
y=x1+x2
function [ x1, x2] = result( c, d )
x1=c+d;
x2=c-d;
Then in Matlab windows command call your function with c and d argument
c=2;
d=3;
y=heatsource(c,d)

카테고리

도움말 센터File Exchange에서 Bloomberg EMSX에 대해 자세히 알아보기

질문:

2014년 4월 28일

댓글:

2020년 7월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by