|
I have written an mfile which repeatedly calls a function to process some data. That function has an on/off switch for plotting, so I can tell the function to plot figures from the data it is processing if I want.
I have found that when my function calls saveas to save a figure, the time taken to save the figure increases each time the function is called from within the m file Each time saveas is called, it is inside of a function, so at the end of each function I would assume that memory is cleared before the function is executed again. If I run my function in a for loop multiple times, the first iteration takes 1 second to save an image, by iteration 10 it takes nearly 1.5 seconds, and by iteration 20 it takes nearly 2 seconds (using tic toc). I need to go through 50 files and have my code save figures for each of them. I am using saveas in the following way:
saveas(positiveFFTfig, filepath);
Where my file path has .jpg at the end of it so it knows to save as a jpeg.
Can anybody tell me why each subsequent figure takes longer to save than the previous one, until my code becomes unbearably slow?
|