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!