how do i re-run a script so that it takes the updated information from another script?

15 ビュー (過去 30 日間)
Samir Mobasher
Samir Mobasher 2019 年 8 月 17 日
コメント済み: Samir Mobasher 2019 年 8 月 17 日
i have 2 scripts open. The first one includes my function. In the second script that calls on my function. If i run the code in the second script and then go back to first script and adjust some of the code, when i go back to second script to run, it doesnt notice the update i made in the first script. The way i have gotten around this is running "clear" and then starting from scratch, but i am assuming there is a cleaner way to do this?
  1 件のコメント
per isakson
per isakson 2019 年 8 月 17 日
編集済み: per isakson 2019 年 8 月 17 日
IMO: Your "program" (/system) shall consist of at most one script (the "main") together with any number of functions. Many collaborating scripts is asking for trouble.
Proposal: Show us your code or better make a minimal working example that illustrates your problem. Then we could try to cast it into a better design.

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

回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 8 月 17 日
MATLAB will normally notice changes to .m files that are on the current path, but not if they are installed under the MATLAB installation directory, and not consistently if you are working with a function handle to the function.
Using clear with the name of the function is the official method of dealing with this.
  2 件のコメント
Samir Mobasher
Samir Mobasher 2019 年 8 月 17 日
thanks. So i have a series of .m files in my current folder. I am completing a course where one of the main files has the majority of the code/instructions, it asks you to then go into the other .m files and input various code for functions. Once that is complete you come back to the main file and run the section of code that relates to that file. My issue is if i have gotten my code wrong and i try to change when i come back main file it doesnt recognise the change. So i normally have to clear everything. I will attempt clear with the function name thanks.
Samir Mobasher
Samir Mobasher 2019 年 8 月 17 日
similarly if i have code in a particular .m file and then i adjust that code and run the function in the command window, its not recognizing the adjusted code, just the code that existed before.

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

カテゴリ

Help Center および File ExchangeSoftware Development Tools についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by