How to pause running program from GUI and assign new variable value?

3 ビュー (過去 30 日間)
Husni
Husni 2012 年 11 月 29 日
for example I have simple program
for x=1:1000;
y=a*x+b*x^2;
end
I want to stop at any number of x and assign new values for a and b. How can I do it from GUI?
regard
Ali

採用された回答

Walter Roberson
Walter Roberson 2012 年 11 月 29 日
You cannot pause a running program. The closest you can get is to put in a breakpoint or a conditional breakpoint before you start running the program.
But possibly you meant something else by "from GUI"; above I was answering about the MATLAB interface to run and debug programs.
If you are constructing a GUI that is starting a routine in a callback, then there is no mechanism in MATLAB to force that routine to pause when the user clicks something (or uses the keyboard.) It is possible, however, to write the routine so that it asks whether the user would like it to pause, or so that it notices that the user has changed values in a user interface and use the new values. To do this, the routine needs to use drawnow() to give the user interface an opportunity to do pending actions, and the routine needs to get() values from the handles in order to receive the updated values. For example,
for x = 1 : 1000
drawnow()
a = str2double(get(handles.editbox_a, 'String'));
b = str2double(get(handles.editbox_b, 'String'));
y(x) = a * x + b * x^2;
end
  3 件のコメント
Walter Roberson
Walter Roberson 2012 年 11 月 29 日
handles.pausebutton = uicontrol('Style', 'radio', 'Value', 0);
for x = 1 : 1000
drawnow()
needpause = get(handles.pausebutton, 'Value');
if needpause
a = input('new a?');
b = input('new b?');
set(handles.pausebutton, 'Value', 0)
end
y(x) = a * x + b * x^2;
end
Husni
Husni 2012 年 11 月 29 日
many thanks walter...it's really helpful

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by