MATLAB Answers

UIFigure Keyboard control update

7 views (last 30 days)
Matlab
Matlab on 5 Dec 2019
Commented: Adam Danz on 6 Dec 2019
I have a input for my uifigure for plotting the data
PlotCntrl = input('+: cont, -: back, a=: auto, q: quit -->', 's')
I need help . My Code is available in the below link

  5 Comments

Show 2 older comments
Adam Danz
Adam Danz on 6 Dec 2019
I'm not sure what you mean by "input". input() is a Matlab function that prompts the user to enter information. The line in your question works but the one in your comment above doesn't because of the axis handle provided in the input.
Sorry, I have no idea what you're trying to do but I'd be happy to help if you can explain it.
Matlab
Matlab on 6 Dec 2019
The idea is to provide input from keyboard for the uifigure
PlotCntrl = input(app.UIAxes,'+: cont, -: back, a=: auto, q: quit -->', 's'); % app.UIAxes is wrong
I was providing the input from command window using keyboard to control variable x and xend using PlotCntrl = input(). If I share the app , then command window is NOT available , so I am looking for an approach on how to provide the input control for the uifigure ?
if strcmp(mode, 'manual')
PlotCntrl = input('+: cont, -: back, a=: auto, q: quit -->', 's');
if strcmp(PlotCntrl, 'a')
mode = 'auto';
elseif strcmp(PlotCntrl, 'q')
x = 0;
elseif strcmp(PlotCntrl, '-')
if x>1, x=x-3; end
else
if x<xend-1, x=x+1; end
end
else
x = x+1;
if x>xend, x = xend; mode = 'manual'; end
end
help input
input Prompt for user input.
RESULT = input(PROMPT) displays the PROMPT string on the screen, waits
for input from the keyboard, evaluates any expressions in the input,
and returns the value in RESULT. To evaluate expressions, input accesses
variables in the current workspace. If you press the return key without
entering anything, input returns an empty matrix.
STR = input(PROMPT,'s') returns the entered text without evaluating expressions.
Adam Danz
Adam Danz on 6 Dec 2019
I think I got it. See my answer.

Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 6 Dec 2019
Edited: Adam Danz on 6 Dec 2019
"I am looking for an approach on how to provide the input control for the uifigure"
Idea 1: add buttons to your App
One approach would be to simply add 4 buttons to your App.
  • Continue
  • Back
  • Auto
  • Quit
Each button could use the same callback function that changes x (or whatever other variables they should affect) depending on which button was pressed.
Idea 2: use uiconfirm()
uiconfirm(f,message,title,Name,Value) is a dialog box that allows the user to select a button option which is returned as an output. Try this.
app.UIFigure = uifigure(); % This is your app, you don't need this line.
selection = uiconfirm(app.UIFigure,'Select something','MyApp',...
'Options',{'Continue','Back','Auto','Quit'}, ...
'DefaultOption','Continue', ...
'CancelOption','Quit');

  7 Comments

Show 4 older comments
Adam Danz
Adam Danz on 6 Dec 2019
It's usually listed at the top of the component browser in AppDesigner.
In the image below, my app figure handle is app.MyAppUIFigure
191206 005628-App Designer - C__Users_adanz_Documents_MATLAB_savehere_my templates_myFakeApp.m.png
Matlab
Matlab on 6 Dec 2019
Perfectly works!! Great support. Thank you. You are a great teacher
Small change in the implementation as shown below
if strcmp(mode, 'manual')
title = 'MyApp';
msg = '+: cont, -: back, a=: auto, q: quit';
PlotCntrl = uiconfirm(app.UIFigure,msg,title,...
'Options',{'+',' -', 'a', 'q'}, ...
'DefaultOption','+', ...
'CancelOption','q');
if strcmp(PlotCntrl, 'a')
mode = 'auto';
elseif strcmp(PlotCntrl, 'q')
x = 0;
elseif strcmp(PlotCntrl, '-')
if x>1, x=x-3; end
else
if x<xend-1, x=x+1; end
end
else
x = x+1;
if x>xend, x = xend; mode = 'manual'; end
end
Adam Danz
Adam Danz on 6 Dec 2019
I'm glad I can help!
Here are some suggestions for improvement
1) I think this looks better and is easier to read:
msg = '[+] cont, [-] back, [a] auto, [q] quit';
2) Instead of a bunch of strcmp()... elseif strcmp().... use a switch-case.
% instead of this....
if strcmp(PlotCntrl, 'a')
mode = 'auto';
elseif strcmp(PlotCntrl, 'q')
x = 0;
elseif strcmp(PlotCntrl, '-')
if x>1, x=x-3; end
else
if x<xend-1, x=x+1; end
end
% I recommend this.....
switch plotCntrl
case 'a'
mode = 'auto';
case 'q'
x = 0;
case '-'
if x>1, x=x-3; end
otherwise
if x<xend-1, x=x+1; end
end

Sign in to comment.

More Answers (0)

Sign in to answer this question.