フィルターのクリア

Adding and display in AppDesigner GUI

1 回表示 (過去 30 日間)
Mai Thành
Mai Thành 2022 年 1 月 7 日
コメント済み: Mai Thành 2022 年 1 月 7 日
I have a small code below to adding and display the value when users press the button. But there is something wrong here, can anyone help me, please
function Button_57Pushed(app, event)
x2=0;
x2=x2 + 1;
app.Label_2.Text='x2 value, x2';
end
Also, the error message said that x2 might be unused.

採用された回答

Kevin Holly
Kevin Holly 2022 年 1 月 7 日
How do you want the text to be displayed?
If you want it to display 'x2 value, 1', you can do the following:
function Button_57Pushed(app, event)
x2=0;
x2=x2 + 1;
app.Label_2.Text=['x2 value, ' num2str(x2)];
end
Not this will always make x2 = 1, since x2 is defined as 0 at the beginning of function. I would remove x2=0 from the function. If you need to preallocate the variable and this is a counter, you need to define it outside the function. You do this in properties (Access = Public). Then you can access the variable with app.x2.
properties (Access = public)
x2 = 0
end
function Button_57Pushed(app, event)
app.x2=x2 + 1;
app.Label_2.Text=['x2 value, ' num2str(app.x2)];
end
  1 件のコメント
Mai Thành
Mai Thành 2022 年 1 月 7 日
Thank you very much !!!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by