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!