Clear Filters
Clear Filters

MATLAB GUI does not finish execution when called from another MATLAB based GUI.

23 views (last 30 days)
Hi Everyone,
I have a MATLAB R2020b gui based application which basically is a menu with buttons and each button press is another MATLAB GUI based executable. The problem is that when I run the main wrapper GUI and press a button, it successfuly launches the executable associated with that. The inner gui based executable is supposed to interface with HW and collect data, save and close and return back the execution to the main GUI. However the problem is that once the inner gui executable saves the data using the save function, it somehow gets frozen, hangs. Nothing happens.
Now here are some other strange observations.
  1. When I run the same deployed setup with extended screens connected to my laptop, it works.
  2. When I run the inner gui directly by double clicking it instead of calling it as a button press from the outer gui, it works.
  3. If I comment out the save function inside the inner GUI, the data doesn't get saved but the program executes and it works.
I have not been able to undestand this weird behavior. Has someone encountered this behavior before ?
Here is the code inside the launcher.exe that executes on a button press and calls another GUI (executbable)
function abc_Callback(hObject, eventdata, handles)
handles.abc.Enable = 'off';
pause(0.2)
try
executablePath = fullfile(handles.rootdirectory, 'folder1', 'folder2', 'abc.exe');
command = sprintf('"%s"', executablePath);
[status] = system(execFileNameWithExt);
catch e
disp(e)
end
handles.abc.Enable = 'on';
Also here is where the save function is run. I added some debug lines before and after the save function and realized that
msgbox('calling "save" function inside generatereport');
save(fullfile(res.Report.reportDir,reportName),'res');
msgbox('executed the "save" function inside generatereport, now on line 99');
now the 2nd msgbox never gets executed. However the save function does save the res object currently at the desired location.
How do you think I should try to debug this problem ? Should i use the logs ?

Accepted Answer

Hassaan
Hassaan on 23 Jul 2024 at 20:04
Edited: Hassaan on 23 Jul 2024 at 20:06
Few of the possible debugging steps may help:
Check File Permissions:
Ensure the save directory has the necessary permissions and is not being accessed by another process.
Simplify the Save Operation:
Test saving a simple variable to a different location to see if the issue persists.
If res is a large object, saving it might take a considerable amount of time or memory. Try saving a smaller subset of res to see if that works.
Debug the Save Function:
Add more debug messages around the save function to isolate the problem.
Log Files:
Use diary or similar logging to create a log file for tracking execution.
System Commands:
Ensure the system call does not interfere with MATLAB execution. Add debugging for system call status and output.
function abc_Callback(hObject, eventdata, handles)
handles.abc.Enable = 'off';
pause(0.2);
try
executablePath = fullfile(handles.rootdirectory, 'folder1', 'folder2', 'abc.exe');
command = sprintf('"%s"', executablePath);
disp(['Executing: ', command]);
% Use system command and capture status and output
[status, cmdout] = system(execFileNameWithExt);
disp(['Status: ', num2str(status)]);
disp(['Command Output: ', cmdout]);
catch e
disp(e)
end
handles.abc.Enable = 'on';
end
Screen Configuration:
Check display settings as the issue might be related to extended screens.
Resource Monitoring:
Use the task manager to monitor resource usage during execution.
MATLAB Updates:
Consider updating to a newer MATLAB version.
Save in Different Format:
Try saving with -v7.3 for large data handling.
Parallel Processing:
Ensure proper configuration if using parallel processing.
  1 Comment
Pratik Chachad
Pratik Chachad on 26 Jul 2024 at 11:16
Thank you @Hassaan. Simplifying the save operation does seem to help but its weird why it works when run as a standalone application but fails when executed from the wrapper

Sign in to comment.

More Answers (0)

Categories

Find more on App Building in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!