Startup value for numeric text fields in app designer

6 visualizzazioni (ultimi 30 giorni)
Jason
Jason il 3 Nov 2022
Risposto: Tridib il 13 Giu 2025
I am trying to create an app with user-editable numeric text fields, but I want the fields in question to load with default values so the app can run without manually entering values into each field. I tried to set the values by using a startupFcn. When I startup the app however, the numeric text fields still contain their default values. Furthermore, calling on the values and using the size() function seems to suggest that it is not getting input correctly. I am still very new to programming, so this is probably a very obvious error on my part, but I have struggled to learn the answer on my own through the documentation, and any help would be greatly appreciated. Here is a sample of the code I'm talking about:
properties (Access = private)
min
max
function startupFcn(app)
app.min = 300
app.max = 800
app.minEditField.Value = app.min
app.maxEditField.Value = app.max
end
sizemin = size(app.min)
sizemax = size(app.max)
minimum = app.min
maximum = app.max
Here is the output from the command window:
app =
struct with fields:
WL_min: 300
WL_max: 800
MinWavelengthnmEditField: [1×1 struct]
MaxWavelengthnmEditField: [1×1 struct]
wlmin =
0 0
wlmax =
0 0
max =
[]
min =
[]

Risposte (1)

Tridib
Tridib il 13 Giu 2025
Hi @Jason,
The code works as expected because the edit fields initially display the default values (300 and 800) when the app starts. These values only change if the user manually enters something. The problem is that you are printing "app.min" and "app.max", which are fixed at 300 and 800 and do not get updated. To check the actual input, print "app.minEditField.Value" and "app.maxEditField.Value" (these values change according to the inputs entered manually) instead. I have verified that the edit fields correctly reflect user input when entered, and otherwise retain their default values.
Hope this helps!

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Prodotti


Release

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by