How does seperate script tell compiled GUI its done

I have a simple Gui I built in App Designer that allows the user to select a file and fill in some text boxes. These box vaules are saved as variables in a mat file which is saved. The run button in the app calls a external script which loads these values into its workspace. The script then processes the file and can save out between 1 a 16 files. I have not been able to find a way to pass the status of the script back to the app as it saves each of the files. Closest I have came is using a msgbox which pops up a window between each file save. This does not work becasue it happens after the fact and either stays open and the next one stacks on top or I use pause and hold it open for x time then close which slows the process. And at the end I would like it to say done but am unsure how to do that either.
%% Point cloud export
% In this part of the code, the scatterplot is exported.
% Defining output document names
filename = sprintf([output_file_name,'_', num2str(iiii)]);
cd(output)
% Write file
pcloud{1,ii} = PC_Final1;
pcwrite(PC_Final1,filename,'PLYFormat','binary');
cd(input)
ref = []; % suppression of the loaded point cloud
f = msgbox((["Processed File:";output_file_name,'_', num2str(iiii) ' of 16\n']),"Status");
pause(10)
if isvalid(f); delete(f); end
How can I have the msgbox close when the next file is saved and after the last one say done?

6 Commenti

How are you invoking the external program? When you invoke it are you waiting for it to finish each time, or are you invoking asynchronously and somehow detecting completion?
In app designer I have a run button. It runs the external script after it populates a text box. I tired adding new text to the box after the script call but it does nothing since I do not know how to tell the script to tell the app its done. So I commented it out. This is why I was triying the msgbox.
% Button pushed function: RunButton
function RunButtonPushed(app, event)
app.ProgressField.Value = "Processing PCAP File, Please Wait";
drawnow;
run 'TLS_PCAP_script';
%app.ProgressField.Value = "Processing Done";
%drawnow;
end
Is an external program being invoked such as using system()?
No. Only the script called by the Run button is being ran. The app is Compiled in app designer to include the script. The mat file with variables resides in the root folder where the app exe resides. This is running and a Windows system.
Unless you are using GPUs or parallel processing, or external processes, then the script does not return to the gui until the script finishes executing. As soon as you get back from the run() the script is finished.
No GPU or Parallel processing. Its just a simple script that I run from the gui and when the script is done the Gui has no idea its done. How can the Gui find out the script is done so that I can tell the user ithe script is done?
Must be a way to send command window text to the app. I tried diary and the script saved a file but it was empty and I am not sure how to tell the app when to read the file if I can get the script side working.

Accedi per commentare.

 Risposta accettata

The solution is trivial: Just add some code to show the progress. Your code was fine and efficient:
app.ProgressField.Value = "Processing PCAP File, Please Wait";
drawnow;
run('TLS_PCAP_script');
app.ProgressField.Value = "Processing Done";
drawnow;
What is your problem with this code? It shows "Please wait" until the script is running and "Done" afterwards.
By the way, using functions instead of scripts is strongly recommended for productive work. Keeping the workspace clean is important.

7 Commenti

The "Processing Done" does not show up after the script is done.
I do not know why unless there is no way for the app to know its done. I am unsure how to tell the app the script is done.
The message boxes do show up at the end of each file that is processed so there is that for progress but I do not know how to make the last one stay on screen. I either get all of them stacked on top of each other or I can delete after preset time. Which of course deletes the final box too. And it could be 1 to 16 files to be processed which means 1 to 16 boxes.
app.ProgressField.Value = "Processing PCAP File, Please Wait";
drawnow;
run('TLS_PCAP_script');
app.ProgressField.Value = "Processing Done";
drawnow;
Would be the best option if I could get it to work.
Yes I know functions would be best but I am slowly learning to program and a good portion of the script was written by someone else. I just rewrote it to do some other things and add a Gui with stand alone version.
Jan
Jan il 30 Mag 2022
Modificato: Jan il 30 Mag 2022
"The "Processing Done" does not show up after the script is done." - This would mean that Matlab does not work. Well. Either your Matlab installation fails completely, or the script does not finish, or the GUIs are not working, or your observation is not correct.
Test this. Replace your script by a pause(2) command and check what happens. Then run just parts of the script.
But maybe you observe a typical effect of scripts: They can and will overwrite locally used variables. If the script contains a clear all or redefined "app" as a struct, the line:
app.ProgressField.Value = "Processing Done";
simply creates a field containing this string.
So I mention again, that it is important not to use scripts for productive work. They make the debugging hard or impossible and increase the complexity of the program while reducing the stability. I assume your problem is caused by using a script, which clears the variable app for any reasons.
Check this:
app.ProgressField.Value = "Processing PCAP File, Please Wait";
whos app
drawnow;
run('TLS_PCAP_script');
whos app % Is it still the handles structure of the GUI?!?
app.ProgressField.Value = "Processing Done";
drawnow;
You mentioned there may be a clear in the script and indeed the original writer had a clear,close,all line at the top. I did not think this would matter and I was wrong.
Once I removed the clear, close,all line in the script all is working as desired.
Thank you for taking the time to help me figure this out ,its very much appreaciated.
Stephen23
Stephen23 il 30 Mag 2022
Modificato: Stephen23 il 30 Mag 2022
"the original writer had a clear,close,all line at the top. I did not think this would matter and I was wrong."
CLEAR ALL CLOSE ALL etc. are anti-pattern programming. The best approach is to use functions, as Jan wrote.
@Donny Mott: The brute clearing header (at least not "clear all") is "cargo-kult programming" and together with scripts it is known to cause exactly the troubles you have been faced with.
If you start programming in Matlab, scripts saves you 2 lines of code and you do not have to think about which variables are needed in the input and output. To avoid confusions with other scripts, clear commands are useful. But as soon as you write code for productive work, these methods cause problems and the debugging is hard.
So I like courses, which start with teaching good programming styles from the first lesson.
Thank you for that. Good advice. Still learning. I have not tried to rewrite the original 300 line script to functions yet. But may once I learn more about programming.
Most likely all you need is to start the code by
function yourMFileName
and append an
end
Maybe some inputs and outputs must be defined.

Accedi per commentare.

Più risposte (0)

Categorie

Prodotti

Release

R2022a

Richiesto:

il 28 Mag 2022

Commentato:

Jan
il 31 Mag 2022

Community Treasure Hunt

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

Start Hunting!

Translated by