error using saveas in fig format
3 views (last 30 days)
Show older comments
Hellow Dear,
I tried to save a figure using saveas in fig format and I got several error messages. Saving the same figure in other format such as jpg is fine.
% plot
for page = 1: num_page
if ci_end(page) > numel(screened_contact)
ci_end(page) = numel(screened_contact);
end
figure(page), clf
sgtitle(' Compare orig vs interpolated stim artifact in data pre-processing')
pageF = nrow_subp*ncol_subp*(page -1); % factor to compensate subplot# after page1
for ci = ci_begin(page) : ci_end(page)
subplot(nrow_subp, ncol_subp, ci-pageF), hold on
%grayColor = [.7 .7 .7];
plot(timevec, ref_EP(ci, :), 'k', "LineWidth", 1)
plot(timevec, prepro_EP(ci, :), 'r', "LineWidth", 1)
title( strjoin([num2str(ci) ', C' num2str(screened_contact(ci)) ', ' region(ci) ', ' region_abbrev(ci)]) )
plot([0 0], get(gca,'ylim'), 'k--', 'linewidth',1)
plot(get(gca,'xlim') ,[0 0], 'k--','linewidth', 1)
%yvalue = max([max(abs(ref_EP(ci,[1:900]))) max(abs(prepro_EP(ci,[1:900]))) ]);
%set(gca, 'ylim', [-1 1]* (yvalue+20))
%set(gca,'xtick',[-0.1 0 0.2 0.4])
%set(gca, 'xticklabels', [-0.1 0 0.2 0.4])
set(gca, 'xlim', [-0.1 0.4])
end
set(gcf, 'Position', get(0, 'Screensize'));
saveas(figure(1), [ char(output(1,:)) '\preprocessed_vs_ref_con' num2str(ci_begin(page)) '_to_' num2str(ci_end(page)) '.fig' ])
saveas(figure(1), [ char(output(1,:)) '\preprocessed_vs_ref_con' num2str(ci_begin(page)) '_to_' num2str(ci_end(page)) '.jpg' ])
close(1)
end
0 Comments
Accepted Answer
Walter Roberson
on 8 May 2024
Notice the error is shown as being on line 14 of savefig
Line 14 of the Mathworks supplied savefig gor R2022b is
% savefig(H,FILENAME,'compact') saves the figures identified by the graphics
So your problem is that you have a third-party savefig.m that is interfering with using saveas()
3 Comments
DGM
on 9 May 2024
The error is not in the builtin axes class. It's in whatever file you named savefig.m, which is trying to take some unknown set of inputs and apply them in some unknown fashion to an axes object.
We can't see that file, so we don't know how it's mishandling the arguments it's given when called incorrectly.
Find the offending file and rename it so that it stops causing the problem.
which savefig -all % look for the file
If there is some other user created file called savefig.m, rename it.
More Answers (0)
See Also
Categories
Find more on Printing and Saving 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!