why is the lamp changing color?

2 visualizaciones (últimos 30 días)
Muazma Ali
Muazma Ali el 4 de Jun. de 2023
Comentada: Muazma Ali el 5 de Jun. de 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)

Respuesta aceptada

VBBV
VBBV el 5 de Jun. de 2023
Editada: VBBV el 5 de Jun. de 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 comentarios
VBBV
VBBV el 5 de Jun. de 2023
Editada: VBBV el 5 de Jun. de 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)
Muazma Ali
Muazma Ali el 5 de Jun. de 2023
@VBBV thanks a lot for your help. Now I understand what I did wrong :)

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 4 de Jun. de 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.

Categorías

Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by