Why is the lamp not changing color?

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 Comments

Cameron
Cameron on 22 Feb 2023
Edited: Cameron on 22 Feb 2023
You need to be a little more specific. You haven't told us what your expected inputs are to either of your .mlapp files. We cannot help you if you don't give us 1) your inputs, 2) your results, and 3) your expected results.
@Cameron ( the boreholestability app is just the front page that is not doing any operations), 1) inputs to the app2 , the number of zones: an integer value, number of salts available is also an input value and if it is less than 2 or more than 3 , the color of the lamp should change to red else it has to be green but mine is not changing color and that is the problem
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..
You can't do this:
app.NumberofsaltsEditField.Value=[]
you must set it to a number, not null or a string.

Sign in to comment.

Answers (1)

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!

Categories

Asked:

on 22 Feb 2023

Answered:

on 11 Jun 2025

Community Treasure Hunt

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

Start Hunting!