Run a line once the code is manually stopped

I have a CFD simulation running and a matlab script that reads the outputs of the simulation in real time and plots the residuals. To do this I designed the code in such a way that I have the script in a folder and the results of the simulations in another, and I move to that folder with command cd(simulation_folder) and then open the files I need to plot.
So, I know this is not the optimal way to do this kind of thing, and I already figured out another way to do it, but I noticed one particular thing that got my curiosity: when I stop the code manually (clicking the red stop button), the path is now changed to the simulation's folder, and I had to reset the path to the matlab script's folder manually in order to run it again.
So the question is: is there a way to execute some lines of code after the stop button is pushed?
for a better explanation I leave this pseudo code:
run the simulation
[...]
%here I click the stop button
% here are the lines I would like to execute after clicking it
if stop_button == clicked
cd(starting_folder)
end

回答 (1 件)

Walter Roberson
Walter Roberson 2023 年 4 月 28 日

0 投票

No direct method is available for this. However you might be able to work it by using onCleanup in a called function.

1 件のコメント

Steven Lord
Steven Lord 2023 年 4 月 28 日
Or if the function you're calling can accept full file names (with the path information) you could use that (constructed with fullfile) instead of changing directory.

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

カテゴリ

ヘルプ センター および File ExchangeFile Operations についてさらに検索

製品

リリース

R2022b

タグ

質問済み:

2023 年 4 月 28 日

コメント済み:

2023 年 4 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by