Error Saving figure: Error using sprintf: Conversion to text from matlab.ui.Figure is not possible.

I want to save a figure containing a tiled layout with images, but the following error occurs every time.
"Error using sprintf: Conversion to text from matlab.ui.Figure is not possible. "
Here is some simplified version of the figure:
load('trees.mat')
fig = figure();
tlo = tiledlayout(fig,1,2,"TileSpacing","compact");
nexttile(tlo);
imshow(X,map);
title('A')
nexttile(tlo);
imshow(X,map);
title('B')
I already tried the savefig function and the saveas function.

댓글 수: 4

Can you show the code where you tried to save the figure (e.g., using savefig or saveas)?
Which line of code gives you the error? And have you copy and pasted the full error message (i.e. all of the red text) ?
It would be better if you can share the code you are working with, as important details about the code seems to have been lost in simplifying it.
This is the full error:
Error using sprintf
Conversion to text from matlab.ui.Figure is not possible.
Error in printf (line 8)
disp(sprintf(str, varargin{:}))
Error in savefig (line 63)
printf('WARN %s: ignoring bad names "%s" "%s"', ...
Error in myfigure (line 14)
savefig(fig, 'test.fig')
The code I am working with contains a huge amount of data and functions I wrote myself, but I broke everything down to this example, which yields exactly the same error.
So I don't think providing the full code would be helpful.
The code, where I tried to save just contains the following additional line:
savefig(fig, 'test.fig')

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

 채택된 답변

Your full error message references line 63 in the savefig function, which in the savefig function included in MATLAB:
which -all savefig
/MATLAB/toolbox/matlab/graphics/objectsystem/savefig.m
dbtype 63 savefig.m
63 % throw the warning
does not match the line you showed. When you run the first command I ran on your machine, what is the result? I'm guessing you wrote your own savefig.m or downloaded one from somewhere else that's taking precedence over the one included in MATLAB, especially since:
which -all printf
'printf' not found.
there is no printf function in MATLAB.

댓글 수: 2

You are completely correct. I used a toolbox which, unbeknownst to me, contained a savefig.m.
Removing the path to the toolbox solved the problem.
Many thanks!
It may be worth contacting the author of the toolbox about this. They may want to consider renaming their functions to avoid such confusion.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

제품

릴리스

R2021b

질문:

2023년 10월 31일

댓글:

2023년 11월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by