error in figure print
1 view (last 30 days)
Show older comments
I am trying to run this code but i get error message
% if figname set, use it; otherwise the data file name
if isfield(cfg, 'figname') && ~isempty(cfg.figname),
set(gcf, 'Name', sprintf('Fig.%d: %s', gcf, cfg.figname), 'NumberTitle', 'off');
elseif isfield(cfg, 'datafile') && ~isempty(cfg.datafile),
slashpos = find(cfg.datafile == '/' | cfg.datafile == '\', 1, 'last');
if ~isempty(slashpos), cfg.datafile = cfg.datafile(slashpos+1:end); end;
set(gcf, 'Name', sprintf('Fig.%d: %s', gcf, cfg.datafile), 'NumberTitle', 'off');
else % shorten the figure name anyway
set(gcf, 'Name', sprintf('Fig.%d', gcf), 'NumberTitle', 'off');
end;
what does this mean?
"Error using sprintf Function is not defined for 'matlab.ui.Figure' inputs"
0 Comments
Accepted Answer
Walter Roberson
on 19 Jun 2022
You have two calls to sprintf in which you ask to format gcf
Change those two gcf to be double(gcf)
2 Comments
Voss
on 3 Jul 2022
cfg = [];
% if figname set, use it; otherwise the data file name
if isfield(cfg, 'figname') && ~isempty(cfg.figname),
set(gcf, 'Name', sprintf('Fig.%d: %s', double(gcf), cfg.figname), 'NumberTitle', 'off');
elseif isfield(cfg, 'datafile') && ~isempty(cfg.datafile),
slashpos = find(cfg.datafile == '/' | cfg.datafile == '\', 1, 'last');
if ~isempty(slashpos), cfg.datafile = cfg.datafile(slashpos+1:end); end;
set(gcf, 'Name', sprintf('Fig.%d: %s', double(gcf), cfg.datafile), 'NumberTitle', 'off');
else % shorten the figure name anyway
set(gcf, 'Name', sprintf('Fig.%d', double(gcf)), 'NumberTitle', 'off');
end
get(gcf,'Name')
More Answers (0)
See Also
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!