need a help...simple question

1 回表示 (過去 30 日間)
Ambreen
Ambreen 2011 年 6 月 12 日
ok lets suppose i write a M-file which have many mathematical formulas etc in it,then i write another M-file and i wish to call that M-file contents in this new file ,how can i do that???is it possible?
i want to do this to make my MATLAB code look small...i mean to avoid long code,just call the desired formula file in a single line and you are done with your code...is it possible? if yes then please explain !
thanx!

採用された回答

Matt Fig
Matt Fig 2011 年 6 月 12 日
Yes you can do this. Any M-file can call any other M-file as long as they are in the same directory or on the path. For example, put all of this into an M-file called myvars:
a_var = 5;
b_var = 7;
t = a_var + b_var;
f_func = @(x) x.^2;
Once this is done, then do this from the command line:
myvars
a_var + 10
f_fun(1:5)
You will see that whatever you define in myvars is available at the command line once the M-file is called. It is the same in another M-file. Just put the line:
myvars
anywhere in the file, then after that line all of the stuff in myvars will be in available in the calling file.
  1 件のコメント
Ambreen
Ambreen 2011 年 6 月 12 日
thanx :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by