フィルターのクリア

Start script at a chosen line

88 ビュー (過去 30 日間)
Ali Komai
Ali Komai 2018 年 9 月 26 日
コメント済み: Rik 2020 年 10 月 26 日
As we know it is not possible to modify a running script. You have to stop the script and restart it for the changes to become active. Now I wonder if it is possible to jump into a script at a chosen line. So one could stop a running process, make the desired changes and then have the program continue in the modified version without running the code before the changed part again.
  4 件のコメント
Alexander. Koutsouris
Alexander. Koutsouris 2020 年 10 月 26 日
Start you script with:
i=0;
if i==0
else
And set the "end" at the point where you want to run the script
Rik
Rik 2020 年 10 月 26 日
@Alexander, that will have the same effect as commenting out code. It would also make more sense to me if you use this instead:
if false
%code that shouldn't run
end
%code that should run
That way you don't interfere with any variable that might be used in the rest of the code.

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

採用された回答

Jan
Jan 2018 年 9 月 26 日
Using a method to stop and re-enter scripts at arbitrary lines would be a meta-interpreter, which runs on top of Matlab. Such a method would be prone to errors and it will be hard to reproduce the results reliably. If you want to run a code with some modifications, create a function and trigger the different methods by using a switch, e.g. controlled by an input argument.
Using structured code and functions is such a great improvement and much more stable than running scripts in dynamically modified pieces, that I cannot imagine, why somebody wants to do it the hard and complicated way.
  1 件のコメント
Ali Komai
Ali Komai 2018 年 9 月 26 日
You are surely right and of course it is better to have the code structured but it is a reoccurring issue for me while debugging. And it is in nature of bugs that they pop up at unforeseen locations in the code. :-) However I got my answer. Thank you!
@Adam: Thank you for pointing this out! I was not aware that editing a function that is not executed at the moment was possible. This will help!
@Rik Wisselink: Thank you for this suggestion. I had the same idea but was wondering if there is another possibility.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by