Startup value for numeric text fields in app designer
5 次查看(过去 30 天)
显示 更早的评论
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 =
[]
0 个评论
回答(1 个)
Tridib
2025-6-13
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!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!