Exportapp causing undefined function "printopt" error

조회 수: 3 (최근 30일)
StefanoM64
StefanoM64 2023년 2월 6일
댓글: StefanoM64 2023년 3월 6일
Hello,
I developed an appplication (with App Designer) that reads real-time data from an instrument and creates a plot.
It worked OK until I added to the code the following command to save a copy of the GUI every 5 minutes:
exportapp(app.MYAPPNAMEUIFigure,'F:\GUI_PLOT.jpg')
every now and then I got the following error message:
undefined function "printopt" for input argument type matlab.ui.Root
I cannot understand what is wrong since the application works for most of the time.
By the way, is there a way to automatically dismiss such error dialogs? I created a Task (in windows Task Scheduler) that re-launch the application if it stops for some reasons, but the error dialog box interfere with it.
Any hints? Thanks!

답변 (1개)

Aishwarya Shukla
Aishwarya Shukla 2023년 3월 1일
Hi @StefanoM64,
The error message "undefined function 'printopt' for input argument type matlab.ui.Root" suggests that there is a problem with the print options for your GUI figure. It seems like the function 'printopt' is not defined or available for the 'matlab.ui.Root' type.
To solve the problem, you could try the following:
  1. Check that the function 'printopt' is available on your MATLAB path. You can do this by typing 'which printopt' in the MATLAB command window. If the function is not found, you may need to add it to your path.
  2. Check that the syntax for the 'exportapp' command is correct. Make sure that you are passing the correct arguments and that the file path is valid.
  3. Try using the 'print' function instead of 'exportapp'. The 'print' function can be used to save a figure to a file. For example, you could use the following command to save the GUI figure as a JPEG image: print(app.MYAPPNAMEUIFigure, 'F:\GUI_PLOT.jpg', '-djpeg')
Regarding the error dialog box, you could try using the 'try...catch' statement to handle the error and prevent the dialog box from being displayed. For example:
try
exportapp(app.MYAPPNAMEUIFigure, 'F:\GUI_PLOT.jpg')
catch
% Handle the error here end
This will try to execute the 'exportapp' command, and if an error occurs, the code inside the 'catch' block will be executed instead. You can use this block to handle the error in a way that suits your application, such as logging the error or displaying a custom error message.
  댓글 수: 3
Aishwarya Shukla
Aishwarya Shukla 2023년 3월 1일
It is possible that the error is caused by a conflict between the 'exportapp' function and other functions or processes running in your application.
One possibility is that the 'exportapp' function is being called at a time when the GUI figure is not fully loaded or initialized, causing the error to occur. To avoid this, you could try adding a short delay before calling the 'exportapp' function, to allow the GUI figure to fully initialize. For example:
pause(0.1); % add a 100 millisecond delay
exportapp(app.MYAPPNAMEUIFigure, 'F:\GUI_PLOT.jpg');
Another possibility is that the 'exportapp' function is causing a memory or resource conflict with other parts of your application. You could try monitoring your system resources (such as CPU and memory usage) during the operation of your application, to see if any resource constraints are being exceeded when the error occurs.
StefanoM64
StefanoM64 2023년 3월 6일
I inserted a pause before the exportapp command, as you suggested.
Now, I've just to wait and check if my app runs smoothly.
Thanks again!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by