Figure in nested loop when turned invisible gives error while trying to use saveas
Show older comments
Due to a large dataset I am using a nested loop to create multiple figures.To prevent it spamming my livescript output side of the screen and decrease run time I am trying to turn the figures invisible. However, when I turn the figure invisible it gives an error at the saveas line. I am currently using fullfig() because it ensure the size of the saved figure but figure() gives the same error so it is used in the code below. In an earlier part of the script I use invisible figures to go from linear models to line objects of which I do not save the figure (only data points) and that works without issues. Due to this I am quite certain adding the invisiblity changes something in how I should save the file but I cannot find how or why and how to fix it. My preffered end result would be for the figures to get exported at max screen size, with the specified name and as png.
The nested loop looks like:
for oor = 2:8
for persoon = 2:5
f100 = figure(); %Ensure the figure is empty at beginning of loop
figure(f100); %Open said figure
subplot(1,4,1) %Open first subplot
hold on
%Code for double y-axis errorbar()
hold off
%And so on until subplot(1,4,4)
%Save figure with name specific to loop based upon array with
%strings
saveas(f100, Pnames(persoon) + "_" + Enames(oor) + ".png")
end
end
So changing
f100= figure();
to
f100 = figure('visible','off');
gives the error
Error using checkArgsForHandleToPrint
Handle input argument contains nonhandle values.
Error in checkArgsForHandleToPrint
handles = checkArgsForHandleToPrint(0, varargin{:});
[pj, inputargs] = LocalCreatePrintJob(varargin{:});
print( h, name, ['-d' dev{i}] )
on line
saveas(f100, Pnames(persoon) + "_" + Enames(oor) + ".png")
where Pnames and Enames are arrays which include strings.
Accepted Answer
More Answers (0)
Categories
Find more on Creating, Deleting, and Querying Graphics Objects 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!