why is the lamp changing color?
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
VBBV
on 5 Jun 2023
Edited: VBBV
on 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 Comments
VBBV
on 5 Jun 2023
Edited: VBBV
on 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)
More Answers (1)
Image Analyst
on 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 Comments
See Also
Categories
Find more on Develop Apps Using App Designer in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!