error in handle when save multiple figures

조회 수: 22 (최근 30일)
JING JIAO
JING JIAO 2019년 8월 14일
댓글: JING JIAO 2019년 9월 11일
I am running a loop to save multiple figures, in one loop the figure is coded as:
subplot(4,3,1)
plot(1:timesteps,S_RT(1:timesteps),'-b');
where S_RT(1:timesteps) is a variable that changes every loop.
then I save this graph as the following where i, jj, k and h indicate the four nested loop:
filename = sprintf('Tran_RT %d vs Tran_WT %d vs Mig %d vs Grow %d.png',i,jj,k,h);
saveas(gcf,filename);
clf;
It sometimes shows error as:
Error using checkArgsForHandleToPrint
Handle input argument contains nonhandle values.
Error in checkArgsForHandleToPrint
Error in print>LocalCreatePrintJob (line 100)
handles = checkArgsForHandleToPrint(0, varargin{:});
Error in print (line 38)
[pj, inputargs] = LocalCreatePrintJob(varargin{:});
Error in saveas (line 181)
print( h, name, ['-d' dev{i}] )
Is that due to I used "subplot"? How can I handle this issue? Thanks in advance.
  댓글 수: 2
Walter Roberson
Walter Roberson 2019년 8월 14일
I would suspect that the clf is getting executed before the saveas() has finished. You might need a pause() to get the saveas() time to execute.
JING JIAO
JING JIAO 2019년 9월 11일
Thanks, this is what I did, it worked.

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

답변 (2개)

Shashank Gupta
Shashank Gupta 2019년 8월 26일
If we look at the error
Handle input argument contains non handle values
A non-handle value is passed when it expected a handle, that in turn is caused by "saveas" function.
The input argument to this function may not be handle anymore. Although you are using clf command to remove the figure, it shouldn’t have caused the problem as clf only remove the graphical content of the figure. Try looking at your code and see if you are removing the figure window as well because that will remove the handle and thus triggered the error. You can also try putting a breakpoint at "saveas" function and run the code. At the breakpoint inspect the values that are passed to "saveas" and check if the proper handle is passed.

Walter Roberson
Walter Roberson 2019년 9월 11일
I would suspect that the clf is getting executed before the saveas() has finished. You might need a pause() to get the saveas() time to execute.
  댓글 수: 1
JING JIAO
JING JIAO 2019년 9월 11일
Thanks. I do put pause before and after clf, it works now.

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

카테고리

Help CenterFile Exchange에서 Modify Image Colors에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by