why is the lamp changing color?
    2 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    Muazma Ali
 am 4 Jun. 2023
  
    
    
    
    
    Kommentiert: Muazma Ali
 am 5 Jun. 2023
            Hi
The lamp in this short app is not supposed to change color when something is typed in the first field ( Nr of zones) because the criterion I have is related to the second field (Nr Of salts). 
Can anybody check and tell me , I have tried to put a condition so that it is supposed to show magenta when the first field (Nr of Zones) is empty . I dont know how to program the app so it lamp color does not change from magenta to red when the user just has typed in Nr of Zones and not reached to the second field (Nr of Salts)
0 Kommentare
Akzeptierte Antwort
  VBBV
      
      
 am 5 Jun. 2023
        
      Bearbeitet: VBBV
      
      
 am 5 Jun. 2023
  
      Hi Mauzmi Ali , 
In the app designer code, the editField component accepts numeric inputs. By default the  Matlab editField component assigns a value 0,  Hence you need to change the code as shown below with additional conditions added in the if  statement. 
if ~isempty(app.antall_soner)
    if (app.NrofsaltsEditField.Value>3) || (app.NrofsaltsEditField.Value>=1 && app.NrofsaltsEditField.Value<2)
        app.Lamp.Color='red';
        app.EditField.Value='Choose minimum 2 salts and maximum 3 salts';
    % if the user inputs salts without number of zone inputs
    elseif (app.NrofsaltsEditField.Value==3||app.NrofsaltsEditField.Value==2) && (app.NrofzonesEditField.Value == 0)
        app.Lamp.Color='red';
        app.EditField.Value='Please enter Number of Zones';
    elseif (app.NrofsaltsEditField.Value==3||app.NrofsaltsEditField.Value==2) && (app.NrofzonesEditField.Value ~= 0)
        app.Lamp.Color='green';
        app.EditField.Value='Input accepted!';
    end
    app.nr_zones_analyzed=app.nr_zones_analyzed+1;
end
2 Kommentare
  VBBV
      
      
 am 5 Jun. 2023
				
      Bearbeitet: VBBV
      
      
 am 5 Jun. 2023
  
			The lamp is changing color due to presence of default value of 0  in the edit field related to app.NrofsaltsEditField.Value  If you observe the if-condition  thats present in your code (shown below), it will always satisfy the condition,  because edit field value is 0 which is less than 2
if (app.NrofsaltsEditField.Value>3) ||  app.NrofsaltsEditField.Value<2)
Hence, you need to modify it as below 
if (app.NrofsaltsEditField.Value>3) || (app.NrofsaltsEditField.Value>=1 && app.NrofsaltsEditField.Value<2)
Weitere Antworten (1)
  Image Analyst
      
      
 am 4 Jun. 2023
        In Numer_of_zonesEditFieldValueChanged you have
app.Lamp.Color='r';
and
app.Lamp.Color='green';
so it's quite possible that changing the number of zones will change the lamp color.
The field cannot be empty.  Your app does not allow it.  It must have something there so you don't need to check for the empty condition.
0 Kommentare
Siehe auch
Kategorien
				Mehr zu Annotations 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!


