フィルターのクリア

How can I call the variable from one MATLAB file into another?

40 ビュー (過去 30 日間)
SIDDESHA H
SIDDESHA H 2016 年 8 月 24 日
編集済み: dpb 2016 年 8 月 24 日
I have say ram.m file, in that file I have the two matrices 'A' and 'B'. In some other file say siddesh.m file, I have two matrices 'C' and 'D'. How can I call these varialbes i.e., A,B,C,D in another .m file.
  1 件のコメント
dpb
dpb 2016 年 8 月 24 日
That's what argument lists and return values are for...read the documentation on functions...

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

回答 (2 件)

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 8 月 24 日
In siddesh.m file Run the file ram.m, just type
ram

SIDDESHA H
SIDDESHA H 2016 年 8 月 24 日
No sir, I should call the varialbes A,B,C,D from two different MATLAB files into another(third) MATLAB file
  1 件のコメント
dpb
dpb 2016 年 8 月 24 日
編集済み: dpb 2016 年 8 月 24 日
Well, either the two files must already return their subject arrays when they're called or you have to rewrite them to do so; if they're functions the variables are local to the function and disappear when the function exits.
[A,B]=ram(whateverItsInputsAre,IfAny);
[C,D]=siddsh(SameStory);
NewResult=fncnThree(A,B,C,D);
Or, of course, you could have fncnThree actually call the two functions internally.
The above presumes the two existing m-files are functions, not scripts. If they are scripts then everything is global (ugh!) and the arrays are already in the workspace; just refer to them as above in the argument list to fncnThree, or if it were again a script, the variables are all directly accessible.
Again, there are many other ways including the use of nested functions, as noted before, read up on scope and lifetime and all the ways functions work and how they compare to scripts.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by