Is it possible to run specific lines from a different script?

6 ビュー (過去 30 日間)
gsourop
gsourop 2020 年 12 月 23 日
回答済み: Walter Roberson 2020 年 12 月 23 日
Dear everyone,
I would like to ask if it possible to code to run specific lines from a script saved in a different directory (than the one I am currently working on) in Matlab?
Thanks in advance.

回答 (2 件)

Hiro Yoshino
Hiro Yoshino 2020 年 12 月 23 日
You need to make the script as function and add the directory of the script to your path as follows:
addpath(genpath("different_directory_path"))

Walter Roberson
Walter Roberson 2020 年 12 月 23 日
Yes. You can read the script as a file, and locate the desired lines, not saving the lines you do not want. Then you can eval() the text.
The portion you extract would have to be self-contained -- e.g., if you extracted a portion that had an "if" but stopped extracting before the corresponding "end" then you would have problems with the eval()
I would suggest to you that this would seldom be a good idea.

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by