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

28 ビュー (過去 30 日間)
vinod kumar
vinod kumar 2014 年 4 月 28 日
コメント済み: drummer 2020 年 7 月 7 日
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 件のコメント
Chandrasekhar
Chandrasekhar 2014 年 4 月 29 日
exactly.
drummer
drummer 2020 年 7 月 7 日
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)

カテゴリ

Help Center および File ExchangeMATLAB Compiler についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by