why is the lamp changing color?
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
VBBV
2023 年 6 月 5 日
編集済み: VBBV
2023 年 6 月 5 日
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 件のコメント
VBBV
2023 年 6 月 5 日
編集済み: VBBV
2023 年 6 月 5 日
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)
その他の回答 (1 件)
Image Analyst
2023 年 6 月 4 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Develop Apps Using App Designer についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!