Why is the lamp not changing color?
3 次查看(过去 30 天)
显示 更早的评论
In the app.2 that the boreholestability app is usig, I have coded a criterion for the lamp to change the color from green to red but it is not changing the color . I am wondering why it is not changing the color..
4 个评论
Image Analyst
2023-2-22
You can't do this:
app.NumberofsaltsEditField.Value=[]
you must set it to a number, not null or a string.
回答(1 个)
Tridib
2025-6-11
Hi @Muazma Ali,
The code is not working as expected because the while loop inside the ValueChanged callback blocks UI updates, as App Designer follows an event-driven model. Also, setting “app.NumberofsaltsEditField.Value = []” inside the loop and reading it right after can lead to an empty value, causing the loop to hang. A better approach would be to handle salt validation in the “NumberofsaltsEditFieldValueChanged” callback, not in the "Number of zones" callback.
Here is a simple workaround that works well:
1. Add two "Edit Fields(Text)", a "Lamp", and a "Text Area".
2. Add the required properties.
3. Use the "NumberofzonesEditFieldValueChanged" callback only to handle the number of zones and create the table.
function NumberofzonesEditFieldValueChanged(app, event)
app.antall_soner = app.NumberofzonesEditField.Value;
sz = [app.antall_soner 6];
varType = ["single", "string", "double", "double", "double", "double"];
varNames = ["Zone_nr", "Combinations_of_salts", "Weight_percent_best_salt_1", ...
"Weight_percent_best_salt_2", "Total_water_activity", "Osmotic_pressure"];
app.Osmotisk_data = table('Size', sz, 'VariableTypes', varType, 'VariableNames', varNames);
app.nr_zones_analyzed = 0;
end
4. Use the "NumberofsaltsEditFieldValueChanged" callback to validate the number of salts, update the lamp color, and update the text area message.
function NumberofsaltsEditFieldValueChanged(app, event)
antall_salter_tilgjengelige = app.NumberofsaltsEditField.Value;
if isempty(antall_salter_tilgjengelige) || antall_salter_tilgjengelige > 3 || antall_salter_tilgjengelige < 2
app.Lamp.Color = 'r';
app.EnterthenragainTextArea.Value = {'Choose a valid input'};
else
app.Lamp.Color = 'green';
app.EnterthenragainTextArea.Value = {'Input accepted!'};
end
5. The rest of the code for the table and value updates can be added as needed.
Hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Identification 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!