The inputdlg stays open

11 Ansichten (letzte 30 Tage)
Ole
Ole am 6 Aug. 2017
Beantwortet: Image Analyst am 7 Aug. 2017
I would like to to have an input window and have the ability to change the input data. The code below uses inputdlg.
The problem is that the graph is not accessible. Is there a way to have access to the graph and to change the input values easily.
while (true)
% block of code here
prompt = {'X from','X to','Y from','Y to'};
promptname = 'test';
numlines = 50;
options.Resize='on';
defaultanswer = {'1', '5', '2', '10'};
answer = inputdlg(prompt, promptname,[1 numlines],defaultanswer, options);
xx = [str2num(char(answer(1))), str2num(char(answer(2)))];
xy = [str2num(char(answer(3))), str2num(char(answer(4)))];
plot(xx,xy)
pause(0.1) ; % allow for ctrl-c
end
I can request a key to be pressed (code from another answer). But is there a way to have both accessible without writing a gui.
currkey=0;
% do not move on until enter key is pressed
while currkey~=1
pause; % wait for a keypress
currkey=get(gcf,'CurrentKey');
if strcmp(currkey, 'return') % You also want to use strcmp here.
currkey=1 % Error was here; the "==" should be "="
else
currkey=0 % Error was here; the "==" should be "="
end
end
  2 Kommentare
Walter Roberson
Walter Roberson am 6 Aug. 2017
Could you expand on what you mean by "the graph is not accessible" ?
Ole
Ole am 7 Aug. 2017
Bearbeitet: Ole am 7 Aug. 2017
The window of the graph can not be manipulated (can not be saved the menus are not active because the focus is on the input window). The graph can not be dragged with the mouse also.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Image Analyst
Image Analyst am 7 Aug. 2017
inputdlg() is a model dialog box and you have it in a permanent loop where is keeps calling inputdlg forever so it never goes away or lets you interact with anything else. Learn how to create a regular GUI with edit fields. See http://blogs.mathworks.com/videos/category/gui-or-guide/ Then have a button where you push it to plot data and the callback for that button will get the numbers from the edit fields. It's trivial.

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by