App that opens new uifigure with zoom function stops responding occasionally

조회 수: 4 (최근 30일)
Shao-Yu Wang
Shao-Yu Wang 2022년 6월 10일
댓글: Shao-Yu Wang 2022년 6월 13일
I built an app in App Designer that allows users to select a range of data in the plot with the zoom function, then returns the trimmed data back to the main app. At first it works fine, but if I call this selectSignalRange function for a few more times by clicking the button, sometimes it just stops responding with no error message. It's not greyed out completely, but nothing happens when you click a button in the app or editor window. You can't even close the window. When this happens the only option is to force quit Matlab completely and start over. I'm quite sure it's not a bug from my code, but how do I make the code stable?
The main app:
~
~
function TrimsignalButtonPushed(app, event)
[app.simSignal, app.signalRange] = selectSignalRange(~~~);
drawnow; pause(0.05); % I read from the internet that this line helps prevent crashes
end
~
~
The function:
function [simSignal, range] = selectSignalRange(simSignal, range)
fig = uifigure; % opens new uifigure window
ax = uiaxes(fig);
drawnow; pause(0.05);
plotSignalinUI;
zoom(ax,'on')
% Create push buttons
uibutton(fig,'push',...
'ButtonPushedFcn', @(~,~)simTrimBtnPushed);
uibutton(fig,'push',...
'ButtonPushedFcn', @(~,~)finishBtnPushed);
uiwait(fig); % To prevent outputs until finish button pushed
function simTrimBtnPushed
range.sim = get(ax,'XLim');
simSignal = ~~~; % Edit this variable
~
~
plotSignalinUI;
drawnow; pause(0.05);
end
function finishBtnPushed
close(fig)
end
function plotSignalinUI
plot(~~~) % Plots stuff in the window
end
end
  댓글 수: 2
Voss
Voss 2022년 6월 11일
Would it be possible for you to share the entire code? Perhaps upload the .mlapp file?
Shao-Yu Wang
Shao-Yu Wang 2022년 6월 13일
Sure. There are several functions, but I only included the relevant ones.

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

답변 (0개)

카테고리

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

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by