Hello Christian,
I understand that the issue you are facing is that the ‘load’ statement is being executed before the completion of ‘saveMatFile.exe’. Since ‘saveMatFile.exe’ is responsible for creating ‘mat_file.mat’, the premature execution of ‘load’ results in an error because the file does not yet exist. Furthermore, you wish to ensure that all output from the ‘disp’ command in ‘saveMatFile.exe’ is displayed in the MATLAB command line window.
When the ‘system’ function is invoked with the ‘start’ command, it launches the specified executable in a separate environment. This means MATLAB will not wait for ‘saveMatfile.exe’ to complete before proceeding to the next command. Consequently, the ‘load’ command is executed before ‘saveMatfile.exe’ has finished running.
When the ‘start’ command is omitted from the ‘system’ call, the ‘system’ function directly requests the operating system to execute the given command. In this scenario, MATLAB pauses and waits for the command to execute completely before it returns the exit status to the ‘status’ variable. Since the operating system oversees the execution, it also ensures that the output from the ‘disp’ command within ‘saveMatfile.exe’ is displayed in the MATLAB command line.
Here is example code that demonstrates the effectiveness of this solution:
saveMatfile.exe
function saveMatfile(path)
disp('This text is from saveMatfile.exe');
Solution.m
status = system(['saveMatfile.exe mat_file.mat']);
disp('Data is loaded after exectution of saveMatfile.exe ');
disp('Data is loaded before exectution of saveMatfile.exe ');
Additionally, here are screenshots showing the desired results:
For more detailed information about ‘system’ function, refer to this documentation :
Hope it helps!