Using variables created by one .m file in another

10 ビュー (過去 30 日間)
Rajashekaran
Rajashekaran 2015 年 4 月 8 日
コメント済み: Rik 2019 年 9 月 8 日
Hello all,
I use two .m files. One called "project.m" and another "move_leg.m" which is basically a function. The "project.m" creates a vector qL1 and I can see it in the workspace. Now I want to use this qL1 in my "move_leg.m" file. Is there any way to access it other than passing it as a argument. I don't want to pass it as a argument because I already have a lot as arguments for the same "move_leg" function.
Here you can see that qL1 is created.

採用された回答

Jeffrey Girard
Jeffrey Girard 2015 年 4 月 8 日
編集済み: Jeffrey Girard 2015 年 4 月 8 日
You can make qL1 a global variable.
For example, on project.m put the following:
global qL1;
qL1 = [-pi/2 -pi/2 0];
And on move_leg.m put the following:
global qL1;
You are now ready to use qL1 on move_leg.m
  2 件のコメント
Martin Permocille
Martin Permocille 2019 年 9 月 8 日
Works for me. Thanks.
Rik
Rik 2019 年 9 月 8 日
A global variable is a bad idea. Why are you opposed to passing it as an argument?

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

その他の回答 (0 件)

カテゴリ

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