Change number of drop downs based on spinner value using matlab app designer?

6 Ansichten (letzte 30 Tage)
I want to plot a variable number of lines. The number of lines will be set by the spinner value. I want three drop downs to appear for each line so that I can specify linewidth, color, and linestyle. So if spinner value = 1, 3 drop downs will appear in one row. If spinner value = 2, 6 drop downs will appear in 2 rows (3 columns), etc. Is it dynamically possible to change the number of drop downs to appear in my GUI? If so, any recommendations to make this happen?
Thanks

Akzeptierte Antwort

Image Analyst
Image Analyst am 19 Okt. 2021
I suggest you place all the drop downs on the figure in App Designer, and then set the visibility of all but the first to off/0/hidden so they aren't shown. Then as you spin the widget, set the visibility of the appropriate drops downs to on/1/shown so that they appear. I think this is much easier than trying to create and place them on the fly.

Weitere Antworten (1)

Cris LaPierre
Cris LaPierre am 19 Okt. 2021
Bearbeitet: Cris LaPierre am 19 Okt. 2021
It's possible. See this page. You may find this blog post instightful as well.
The hard part is going to be dynamically coming up with the position of the drop boxes.
  2 Kommentare
James Nestler
James Nestler am 20 Okt. 2021
Thanks for both of your answers. I'll look into Image Analysts' today. I'm new to the app designer features so am not sure how to interpret the error I got yesterday. I made the first row of buttons/fields etc. that I want, and I want to add rows with the spinner. The app I'm designing is called VolumeApp2. The spinner value is set at 1 upon initialization, then I click it to 2.
Yesterday I tried the following:
% Value changed function: NoofSurveysSpinner
function NoofSurveysSpinnerValueChanged(app, event)
value = app.NoofSurveysSpinner.Value;
for i = 2:value
% Create EditField_25
app.(['SurveyLabel' num2str(value)]) = uieditfield(app.Plotter2Tab, 'text');
app.(['SurveyLabel' num2str(value)]).Position = [243 407-20*value 100 22];
% Create BrowseButton_16
app.(['SurveyBrowse' num2str(value)]) = uibutton(app.Plotter2Tab, 'push');
app.(['SurveyBrowse' num2str(value)]).Position = [171 407-20*value 60 22];
app.(['SurveyBrowse' num2str(value)]).Text = 'Browse';
end
end
and got the following error:
Unrecognized property 'SurveyLabel2' for class 'VolumeApp2'.
Error in VolumeApp2/NoofSurveysSpinnerValueChanged (line 469)
app.(['SurveyLabel' num2str(value)]) = uieditfield(app.Plotter2Tab, 'text');
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 453)
Error while evaluating Spinner PrivateValueChangedFcn.
Could someone please advise as to what this error means and how to avoid it?
Thanks again
Cris LaPierre
Cris LaPierre am 20 Okt. 2021
I don't believe you can dynamically create app properties (but have not confirmed that). At the least, this page shows you the way you are intended to create app properties.
If you follow Image Analysts' suggestion, then you will not have to dynamically create component object handles.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by