Why is the lamp not changing color?

8 visualizzazioni (ultimi 30 giorni)
Muazma Ali
Muazma Ali il 22 Feb 2023
Risposto: Tridib il 11 Giu 2025
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 Commenti
Muazma Ali
Muazma Ali il 22 Feb 2023
I am now attaching a shorter code within the app2 file so it is easier for people to see what I have done. Right now I am just bothered about the lamp problem so therefore, I shortened the code..
Image Analyst
Image Analyst il 22 Feb 2023
You can't do this:
app.NumberofsaltsEditField.Value=[]
you must set it to a number, not null or a string.

Accedi per commentare.

Risposte (1)

Tridib
Tridib il 11 Giu 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!

Categorie

Scopri di più su Data Type Identification in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by