Why is the lamp not changing color?
    8 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
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
  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.
Risposte (1)
  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! 
0 Commenti
Vedere anche
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!



