How can I change spinners step size?

I am developing a MATLAB GUI using app designer andI am trying to make an app which includes Button Group and Spinner. What I want to do is that when specific button is chosen it changes step size but when I change to another button it would still hold previous value and add new values to that. My function looks like this.
properties (Access = public)
X = 0;
Y = 0;
Z = 0;
end
% Value changed function: Spinner
function SpinnerValueChanged(app, event)
if app.mVButton.Value == 1
app.Spinner.Step = 0.001;
app.X = app.Spinner.Value;
app.Spinner.Value = app.X + app.Y + app.Z;
elseif app.mVButton_2.Value == 1
app.Spinner.Step = 0.01;
app.Y = app.Spinner.Value;
app.Spinner.Value = app.X + app.Y + app.Z;
else
app.Spinner.Step = 0.1;
app.Z = app.Spinner.Value;
app.Spinner.Value = app.X + app.Y + app.Z;
end
end
end
Many thanks in advance.

 Accepted Answer

I managed to solve the issue. Here is the code for it.
% Value changed function: Spinner
function SpinnerValueChanged(app, event)
previousValue = event.PreviousValue;
app.Spinner.Value = (app.Spinner.Value + (app.Spinner.Value - previousValue));
value = app.Spinner.Value;
if value > 0
app.Spinner.Value = -2;
elseif value < -2
app.Spinner.Value = -0;
end
end
% Value changing function: Spinner
function SpinnerValueChanging(app, event)
changingValue = event.Value;
if changingValue > 0
app.Spinner.Value = -2;
elseif changingValue < -2
app.Spinner.Value = 0;
end
end
% Selection changed function: ButtonGroup
function ButtonGroupSelectionChanged(app, event)
if app.mVButton.Value == 1
app.Spinner.Step = 0.0005; %needed to divide by 2
elseif app.mVButton_2.Value == 1
app.Spinner.Step = 0.005; %needed to divide by 2
else
app.Spinner.Step = 0.05; %needed to divide by 2
end
end
end

1 Comment

Thank you Justus. Btw, it's just-us in this mathworks thread.

Sign in to comment.

More Answers (0)

Categories

Find more on Mathematics and Optimization 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!