read few lines from one *.m file and jump to another *.m file

3 ビュー (過去 30 日間)
Megha
Megha 2018 年 4 月 16 日
コメント済み: Megha 2018 年 4 月 18 日
Is it possible to read only few lines from one matlab code and then jump to another matlab code and read there another few set of lines and so on?

採用された回答

Jan
Jan 2018 年 4 月 16 日

This is not the purpose of program code. If you need only some lines of a specific function, create a copy of this functions and remove the other lines. Fortunately there are no magic GOTO or COMEFROM commands in Matlab. Reading the files by fileread and evaluating some lines by eval is a very bad idea also, because you would create a Meta-Matlab-Interpreter, which is too indirect and prone to bugs to be used efficiently.

  6 件のコメント
Stephen23
Stephen23 2018 年 4 月 18 日
編集済み: Stephen23 2018 年 4 月 18 日
@Megha: no, there is not easy way to do that. It would be possible using some highly inefficient, slow, and likely buggy file reading and evaluation, but that would be an incredibly bad way to run code, and I would not recommend doing that. That is why Jan has also been advising you to use standard control statements, e.g. if or switch. Standard control statements are simple, efficient, and easy to debug. In fact that is exactly what control statements are for: for controlling which code runs. You should use them.
You should avoid doing the kind of magic that you are trying to do.
Megha
Megha 2018 年 4 月 18 日
@Stephen: Thank you very much for your response. I will go with your suggestion.

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

その他の回答 (0 件)

カテゴリ

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

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by