MATLAB app designer button

조회 수: 55 (최근 30일)
lital levy
lital levy 2022년 8월 29일
편집: Ankit 2022년 8월 30일
hi, in the app designer i created a 'start' button that starts the action of a long loops, and i want to create a 'stop' button that will immidietly stop the action of the first button and not waite until it finished the loops, is that possible?

채택된 답변

Ankit
Ankit 2022년 8월 29일
편집: Ankit 2022년 8월 30일
Please find attached *.zip file where you can see one example (refer below code)
properties (Access = public)
stop_sim = false;
end
methods (Access = private)
function stopSimulation(app)
app.stop_sim = true;
msgbox('simulation stopped');
end
function startSimulation(app)
i = 0;
while i<=1000000 && app.stop_sim == false
app.display.Value = num2str(i);
pause(0);
i = i + 1;
end
end
end
function StartButtonPushed(app, event)
startSimulation(app)
end
function StopButtonPushed(app, event)
stopSimulation(app)
end
Once the user pushes the StopButtonPushed button, for which the function "stopSimulation" is a callback, then the app fetch the updated properties and the condition to app.stop_sim will be set to true and hence this allows the app to terminate the while loop before reaching 1000000 iterations.
  댓글 수: 2
lital levy
lital levy 2022년 8월 29일
thank you,but its a long loop and it would stop only when it get to this line in the code, i need it to stop immidiatly when i push the button
Ankit
Ankit 2022년 8월 29일
above function will break the loop as soon as you click the stop button right?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by