Why is the lamp not changing color?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Image Analyst
am 22 Feb. 2023
You can't do this:
app.NumberofsaltsEditField.Value=[]
you must set it to a number, not null or a string.
Antworten (1)
Tridib
am 11 Jun. 2025
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 Kommentare
Siehe auch
Kategorien
Mehr zu Data Type Identification 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!