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.

 Réponse acceptée

Justus Kleine
Justus Kleine le 31 Juil 2019
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 commentaire

Nima Abbasi
Nima Abbasi le 18 Fév 2021
Thank you Justus. Btw, it's just-us in this mathworks thread.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Mathematics and Optimization dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by