Effacer les filtres
Effacer les filtres

Setting properties for uicontrols using for loop

3 vues (au cours des 30 derniers jours)
rmpirooz
rmpirooz le 31 Mai 2023
Commenté : Luca Ferro le 16 Juin 2023
Dear friends, I am working on a GUI where user have to input an integer between 1 and 10. Depending to the input, I have to set the visibility of some uicontrols to "on". Since each time user may input different integer, I have to change the visibility of uicontrols. How can I do this using a for loop or any other way?

Réponses (1)

Luca Ferro
Luca Ferro le 31 Mai 2023
You don't really need a loop.
Scenario 1: Numeric Edit field/Dropdown/Slider/... + Apply button
Ater the user has chosen the input, you can make him press an Apply (push button) button to actually perform the changes. The push button callback will take the input value, perform the checks and then change the visibilities of the wanted components.
It will look more or less like this:
function applyButtonPushedCallback(app,event)
%example of an edit field,keep in mind that you have to check the returned type. Some elements directly return int,
%other elements return cells, string, ...
chosenIn=app.NumericEditField.Value;
switch chosenIn
case 1
%do something
app.ThisEditField.Visible='on';
case 2
%do something
%... all other cases
end
end
Scenario 2: Numeric Edit field/Dropdown/Slider/... + ValueChangedCallback
The value changed callback by definition triggers everytime the value of the selected component changes. It will look basically the same as the one before but you don't need the apply button.
function dropDownValueChangedCallback(app,event)
%example of an edit field,keep in mind that you have to check the returned type. Some elements directly return int,
%other elements return cells, string, ...
chosenIn=event.Value;
switch chosenIn
case 1
%do something
app.ThisEditField.Visible='on';
case 2
%do something
%... all other cases
end
end
  2 commentaires
rmpirooz
rmpirooz le 14 Juin 2023
This doesn't work for me. I have 10 rows of edit boxes where each row has 16 edit boxes. Suppose user enters 8. I have to set visibility of 8*16 edit boxes on and the remaining off. This requires 10*16 lines of code like the following:
set(handles.tag_edit_box1,'visible','on'
Since user may enter any integer between 1 and 10, this means 1600 lines of codes. I need something more efficient, since there are some similar situations and if I use a switch statement, I have to code thousands of lines
Luca Ferro
Luca Ferro le 16 Juin 2023
well this is a totally different matter compared to the absolutely generic description you gave before. Please share your code or app since, at least to me, is not really clear what you are trying to do. Honestly i'm not even really sure that having 160 edit boxes is the way to go in any case, maybe we can rethink the setup as well.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Produits


Version

R2012b

Community Treasure Hunt

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

Start Hunting!

Translated by