Clear Filters
Clear Filters

Slider or spinner changing value from an own specified array in app designer.

23 views (last 30 days)
I would like the values that change when you drag a slider or Spinner in app designer to change values from a custom array.
(Slider step values from an own specified array).
Component Slider and Spinner in app designer.
For exampel an array like this, [0.01 0.12 1.23 2.03. 4.23 .... 9.99].
Can i do that? And if so, how do I do it?

Answers (1)

Imran
Imran on 3 Jan 2023
Edited: Imran on 3 Jan 2023
Hello Lars,
I understand that you want the values that change when slider or spinner is dragged, to change from a custom array.
The design of spinner or slide web widget does not allow varying the step size. It has to be constant for a particular slider or spinner. That is why step values can't be taken from a custom array.
However there is a workaround to accomplish the functionality you are looking for. We can get values from a custom array when we drag a slider or spinner. Refer to the code snippet below for the implementation details.
% Value changing function: Spinner
function SpinnerValueChanging(app, event)
changingValue = event.Value;
app.Spinner.Step = 1;
array = [0.01 0.12 1.23 2.03 4.23 9.99];
if changingValue<=size(array,2) && changingValue>=1
app.EditField.Value = array(1,changingValue);
end
end
Here, the displayed value is stored in an edit field, as an example. We can utilize the spinner value as an index to the custom array. So everytime the spinner value changes, the edit field stores the value from the custom array. You can use some other way to store the output too, but general idea will remain the same.
I hope this helps.
  1 Comment
S. Hannan
S. Hannan on 8 Nov 2023
Is it possible to show the value of Edit Field in the place of Spinner value? I mean is it possible to combine both of them so that instead of showing the spinner's value, the Edit Field's value is visible?

Sign in to comment.

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!