Cannot break the while loop due to imagedatastore
Afficher commentaires plus anciens
Hi all,
I have build a simple app (appdesigner) which looks for new images in specific network storage and processess the data.
Since I am doing the searching for new files in a while loop I wand to be able to break when a stop button is pushed. The code looks following:
The issue I have is that the code works well till I add the dir_content2 in a while loop. Since then I cannot close the app other way than ctrl+C.
It looks that using imagaDatastore object to check the directory content is the issue. Any ideas what is happening?
EDIT: I found that when I use pause(0.1) at the end of the loop, it is possible to do do the break.
properties (Access = public)
stop_sim = false;
modelName;
model;
net;
anchors;
classNames;
executionEnvironment;
folder;
dir_content;
filenames;
current_files;
DB_address;
DB_port;
tablename;
conn;
StopValue;
end
methods (Access = private)
function stopSimulation(app)
app.stop_sim = true;
msgbox('Application stopped');
app.delete;
end
function startSimulation(app)
i = 0;
ExitCount = 1;
% i=0;
counter = 1;
while i<=1000000 && app.stop_sim == false
i = i +1;
counter = 1;
counter = counter+1;
dir_content2 = imageDatastore(app.folder, "IncludeSubfolders",true);
%% processing parth goes here
end
end
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: StartButton
function StartButtonPushed(app, event)
app.status.Value = ('loading data');
app.StopValue = 0;
app.ImageAxes.Visible = 'off';
app.ImageAxes.Colormap = gray(256);
axis(app.ImageAxes, 'image');
%% YOLO model
%% configuration
%#exclude appconfig.txt
Config = fileread('appconfig.txt')
config = split(Config);
app.status.Value = ('waiting for new files');
app.folder = config{3};
app.DB_address = string(config{6});
DBport = config{9};
app.DB_port = str2double(DBport);
app.dir_content = imageDatastore(app.folder,"IncludeSubfolders",true);
app.filenames = app.dir_content.Files;
app.current_files = app.filenames;
%% database;
startSimulation(app)
end
% Button pushed function: StopButton
function StopButtonPushed(app, event)
stopSimulation(app)
end
end
% Component initialization
methods (Access = private)
% App creation and deletion
methods (Access = public)
% Construct app
function app = IMAD_app_07
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Startup and Shutdown dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!