error in figure print
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Walter Roberson
2022-6-19
You have two calls to sprintf in which you ask to format gcf
Change those two gcf to be double(gcf)
2 个评论
Voss
2022-7-3
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')
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!