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

22 views (last 30 days)
vinod kumar on 28 Apr 2014
Commented: drummer on 7 Jul 2020
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
##### 0 CommentsShow -2 older commentsHide -2 older comments

Sign in to comment.

### Accepted Answer

Chandrasekhar on 28 Apr 2014
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 CommentsShow 1 older commentHide 1 older comment
Chandrasekhar on 29 Apr 2014
exactly.
drummer on 7 Jul 2020
Should result.m and heatsource.m be in the same folder so heatsource.m can read x1 and x2?

Sign in to comment.

### More Answers (2)

Andrei Bobrov on 29 Apr 2014
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
##### 0 CommentsShow -2 older commentsHide -2 older comments

Sign in to comment.

Azzi Abdelmalek on 28 Apr 2014
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)
##### 0 CommentsShow -2 older commentsHide -2 older comments

Sign in to comment.

### Categories

Find more on MATLAB Compiler in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!