フィルターのクリア

Why is the lamp color and label not changing according to the if statement?

12 ビュー (過去 30 日間)
Muazma Ali
Muazma Ali 2024 年 1 月 7 日
コメント済み: Muazma Ali 2024 年 1 月 8 日
Hi! :)
I have this code ( see the attached code) within the callback function of one button that I have in my app.
As you can see I am bringing up antall soner from another app.
What I dont understand is why the lamp color and label statement is not changing according to the if statement.
Can anybody help me with my issue?

回答 (1 件)

Voss
Voss 2024 年 1 月 7 日
編集済み: Voss 2024 年 1 月 7 日
The lamp and label change inside a while loop. To see the changes as the code runs, you need to add drawnow after setting their properties, which updates the graphics immediately.
Another problem is that osmotisk_verdi is a character vector, so you don't want to be comparing it to numeric values. You can use str2double to make it numeric, but if app.Osmotic_pressure is numeric you can just use that instead (see comments in the code below).
app.zone_now=0;
while app.zone_now<=app.Callingapp.antall_soner
% assuming app.Osmotic_pressure is numeric, then to update the
% uieditfield, do one of the following:
% if the uieditfield is 'numeric' style, use app.Osmotic_pressure directly:
app.ComputedosmoticpressureEditField.Value=app.Osmotic_pressure;
% or if the uieditfield is 'text' style, use num2str(app.Osmotic_pressure):
app.ComputedosmoticpressureEditField.Value=num2str(app.Osmotic_pressure);
% and you can use app.Osmotic_pressure directly in your comparisons:
if app.Osmotic_pressure <= 30000000
app.Label.Text='Too low osmotic pressure';
app.Lamp.Color='red';
elseif app.Osmotic_pressure < 50000000
app.Label.Text='Intermediate osmotic presssure';
app.Lamp.Color=[1 1 0];
else
app.Label.Text='Beneficial osmotic pressure';
app.Lamp.Color=[0 1 0];
end
% update the GUI:
drawnow();
app.zone_now=app.zone_now+1;
end
  4 件のコメント
Muazma Ali
Muazma Ali 2024 年 1 月 8 日
Am I supposed to use something else together with drawnow as the color has to change inside a while loop.? :)
Muazma Ali
Muazma Ali 2024 年 1 月 8 日
@Voss forget it, I had to lamps in my apps and I just realised it :)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by