필터 지우기
필터 지우기

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

추가 답변 (0개)

카테고리

Help CenterFile 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!

Translated by