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 件のコメント

Voss
Voss 2023 年 10 月 31 日
Can you show the code where you tried to save the figure (e.g., using savefig or saveas)?
Dyuman Joshi
Dyuman Joshi 2023 年 10 月 31 日
編集済み: Dyuman Joshi 2023 年 10 月 31 日
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.
Hannes
Hannes 2023 年 10 月 31 日
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 件のコメント

Hannes
Hannes 2023 年 11 月 1 日
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!
Harald
Harald 2023 年 11 月 2 日
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 ExchangeCreating, 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