Parallel processes in MATLAB App Designer
15 次查看(过去 30 天)
显示 更早的评论
I am doing an app, which has a loop that is being performed each 10 seconds (it is an infinite loop with a flag to exit and has a 10 sec pause). Also, in the app I have a button which callback starts another matlab script. While the script is running, it is writing its "progress" to the .txt file (this is just a float type number).
The idea is that while the script is running, the app reads this number each 10 seconds from the .txt file and shows it in an edit field box. However, while the app is running, as I push the button which starts the matlab script, no changes in Edit Field appear, even though the numbers in the .txt file change. As soon as the matlab script finishes, Edit field shows 100% (the latest number). It seems like App Designer performs the whole matlab script first, while holding the loop on a pause, and starts it again only after the script is finished.
On some different websites I read that those processes should go in parallel (without any additional toolboxes). Is that right? What should I do in order to make Edit Field update "online" with the script processing?
I know that there is a command "drawnow", but I do not know, where to put it, since the loop is being frozen. Relevant parts of the code are below:
This is a loop:
function imaging(app)
progres_path = strcat(app.Directory,'/progres.txt'); %reaching for the .txt file
progres = fopen(progres_path, 'r'); %opening for reading
while ~(app.ExitLoopFlag) %exit loop flag (true before the app is being closed)
if isfile(strcat(app.Directory,'/New_Net/VGG_new_results.mat'))
load(strcat(app.Directory,'/New_Net/VGG_new_results.mat'),'FPR', 'TPR','AUC', 'val_accuracy', 'sensitivity', 'specificity');
cla(app.UIAxes,'reset');
app.UIAxes.GridAlpha = 1;
plot(app.UIAxes,FPR,TPR,'Color','r','LineWidth',2);
leg = strcat('AUC = ', num2str(AUC));
legend(app.UIAxes, leg);
xlabel(app.UIAxes,'False positive rate');
ylabel(app.UIAxes,'True positive rate');
title(app.UIAxes,'ROC Curve');
app.ExitLoopFlag = true;
app.AdddirectoriesButton.Enable = 'on';
app.RetrainthenetButton.Enable = 'on';
end
pause(10); %waiting for 10 seconds for the next loop iteration
percentage = fscanf(progres, '%s'); %reading data from file
result = strcat(percentage, ' %'); %forming a string
app.ProgresspreprocessingEditField.Value = result;
drawnow; %trying to push the changes (doesn't work)
end
fclose(progres); %closing the file
app.ProgresspreprocessingEditField.Value = 'Done!';
progres = fopen(progres_path, 'w');
fprintf(progres,'%s', '0');
fclose(progres);
percentage = '0.0';
progres = fopen(progres_path, 'r');
while str2double(percentage) < 99.99
percentage = fscanf(progres,'%s');
result = strcat(percentage, ' %');
app.ProgresstrainingEditField.Value = result;
drawnow;
end
fclose(progres);
app.ProgresstrainingEditField.Value = 'Done!';
end
This is the callback:
function RetrainthenetButtonPushed(app, event)
% Disable Plot Options button while dialog is open
app.RetrainthenetButton.Enable = 'off';
app.AdddirectoriesButton.Enable = 'off';
%starting preprocessing
preprocessing = strcat(app.Directory,'/preprocessing_ML_v3.m'); %matlab script
eval(['run(''' preprocessing ''');']); %starting the matlab script
end
0 个评论
另请参阅
类别
在 Help Center 和 File 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!