Change "Items" in a Discrete Knob with another knob

11 views (last 30 days)
Douglas Anderson
Douglas Anderson on 11 Sep 2019
Commented: Adam Danz on 23 Apr 2020
I have a test App in App Designer, with 2 Discrete knobs, Knob and Knob2. I want to change the settings ("Items") on "Knob" by moving "Knob2". This was just set up in App Designer, and the following Callback for "Knob2" added with the switch. Why doesn't this work?
methods (Access = private)
% Value changed function: Knob2
function Knob2ValueChanged(app, event)
value = app.Knob2.Value;
switch value
case '1-10'
case '11-20'
case '21-30'
Doug Anderson
  1 Comment
Adam on 11 Sep 2019
What is 'value' if you put a breakpoint in? What does happen given you say it doesn't work?
I've never worked with knobs in app designer, but it would surprise me if the 'value' field evaluated to '1-10' as a char.

Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 11 Sep 2019
Edited: Adam Danz on 11 Sep 2019
For Knobs (continuous)
There are a few things wrong with your callback function. I've listed them in order of importance.
  1. The "Value" of your switch-case is numeric but your cases are character vectors so none of the cases will ever be chosen. Use a series of if-elseif conditionals. You could also use a switch-case with logical comparisons as in this answer.
  2. "Items" is not a property of a knob. Instead, use the "MajorTicks" property which expects a vector (not a cell array).
  3. In addition to MajorTicks, set the "Limits" propery to maximize the full range of your knob
  4. The "value" property expects a scalar, not a cell.
Here's how the callback should appear (showing 1 line, you can adapt the rests)>
if value >=1 && value <= 10
% set()
% set()
For "Discrete Knobs"
  1. The 'Items" property is expected to be a cell array of strings or chars. You can use num2str with strsplit to convert your numeric vector to a cell array of chars.
  2. The "value" property is expected to be a char array that belongs to the updated Items list.
Here's how the callback should appear (showing 1 line, again)
switch value
case '1-10'
Adam Danz
Adam Danz on 23 Apr 2020
I suggest making a new question. You can copy the URL to the new question here so I know where to look when I get the time to look at it (tomorrow, likely).

Sign in to comment.

More Answers (0)




Community Treasure Hunt

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

Start Hunting!

Translated by