how to save a plot ?

I have two large data sets. Usually it takes a lot of time to save a plot on hard drive. I wonder how I can save a plot as jpeg file in a quick way. Usually it takes a lot of time to save a plot on hard drive. I apperciate your help.
saveas(gcf,'C:\plot.jpg')
delete(gcf)

5 Comments

Hassan
Hassan on 19 Jun 2011
I think the problem is about just saving the data. I didnt use the saveas function and it was much faster.
saveas() requires rendering the plot; it is almost always faster to save() the plot data rather than rendering it.
Hassan
Hassan on 19 Jun 2011
you mean there's another function called save(). If so, I couldn't find it.
save() is the counterpart of load()
http://www.mathworks.com/help/techdoc/ref/save.html
It stores the data instead of the image, so whether it is useful to you depends on what you need to do afterwards.
Hassan
Hassan on 20 Jun 2011
I see, it's not the one I need then.

Sign in to comment.

Answers (2)

Jan
Jan on 19 Jun 2011

1 vote

I guess that it is not the saving, but the drawing of the plot, which consumes the most time. "delete(gcf)" means, that you create a new figure for each plot. This is much slower than using the same figure and only update the axes object, or even better: Keep the axes also and update just the children.
So please insert a DRAWNOW before the method for sving and use the PROFILEr to find the most time consuming lines.

6 Comments

Hassan
Hassan on 19 Jun 2011
Thanks Jan. I used DRAWNOW before saveas() function in the code. it didn't make the code to excute faster. I also used profile (profile on -history) in the beginning of the code or more precise in the begining of the loop. it showed that saves, prin, graphics\private\render and harcopy functions take longer to execute, each of them takes 3 min to finish their job.
Jan
Jan on 19 Jun 2011
DRAWNOW cannot accelerate the processing, but it flushs all former drawing commands. Without DRAWNOW the update of the figure is done inside the procedure for saving, such that the profile gets wrong timings.
Can you post the results of the profiler or relevant parts of the code? What is "prin"?
Hassan
Hassan on 19 Jun 2011
sorry, it is 'print'. this is the profile summary:
Function Name Calls Total Time Self Time* Total Time Plot
(dark band = self time)
saveas 1 222.095 s 0.015 s
print 1 222.080 s 0.000 s
graphics\private\render 1 220.485 s 0.000 s
hardcopy 1 220.470 s 220.470 s
xlswrite 4 13.406 s -0.000 s
xlswrite>ExecuteWrite 4 12.329 s 12.283 s
Hassan
Hassan on 19 Jun 2011
actxserver 4 1.047 s 1.047 s
graphics\private\prepare 1 0.828 s 0.765 s
graphics\private\restorehg 1 0.719 s 0.687 s
graphics\private\restore 1 0.719 s 0.000 s
specgraph.scattergroup.refresh 2 0.500 s 0.500 s
...ph.scattergroup.schema>LdoDirtyAction 3 0.500 s 0.000 s
workspacefunc 8 0.108 s -0.000 s
workspacefunc>getStatObjectsJ 4 0.077 s 0.030 s
graphics\private\preparehg 1 0.063 s 0.000 s
scatter 1 0.047 s 0.016 s
graphics\private\fireprintbehavior 2 0.047 s 0.015 s
workspacefunc>getStatObjectJ 256 0.047 s -0.000 s
xlswrite>activate_sheet 4 0.046 s 0.046 s
hggetbehavior 364 0.032 s 0.032 s
workspacefunc>createComplexScalar 252 0.032 s 0.016 s
workspacefunc>num2complex 362 0.032 s 0.000 s
lsline 1 0.031 s 0.016 s
fileparts 12 0.031 s 0.031 s
workspacefunc>getShortValueObjectsJ 2 0.031 s 0.015 s
workspacefunc>getStatObjectM 256 0.031 s 0.000 s
workspacefunc>local_max 94 0.031 s 0.031 s
num2str 18 0.016 s 0.016 s
graphics\private\name 1 0.016 s 0.000 s
spa_sf 1 0.016 s 0.016 s
xlabel 4 0.016 s 0.016 s
findall 14 0.016 s 0.016 s
specgraph.scattergroup.scattergroup 1 0.016 s 0.016 s
kurtosis 2 0.016 s 0.016 s
graphics\private\restoreui 1 0.016 s 0.016 s
graphics\private\inputcheck 1 0.016 s 0.000 s
cell.strmatch 2 0.016 s 0.000 s
strmatch 2 0.016 s 0.016 s
gra...rivate\inputcheck>LocalCheckDevice 1 0.016 s 0.000 s
savtoner
So effectively the bulk of the time is being used in the built-in function toolbox/matlab/graphics/hardcopy which is being called by the plot renderer.
Hassan
Hassan on 20 Jun 2011
it take longer than it shows on profiler. I tried that and when I dont save the plot, it's much faster (although not quite fast).

Sign in to comment.

Walter Roberson
Walter Roberson on 19 Jun 2011

0 votes

There is a possibility that Oliver's export_fig might be faster; it's worth a try.

3 Comments

Hassan
Hassan on 19 Jun 2011
thanks Walter, but it takes about the same time to save the plot.
Hmm... what kind of scene elements do you use? If you do not have transparency, then _possibly_ changing the renderer property of the figure or the drawmode property of axes could help. Unfortunately I do not know how rendering is done for saving images, so these things might not make any difference.
Hassan
Hassan on 19 Jun 2011
sorry Walter, I didnt understand the meaning of scene elements, transprancy and renderer. but will have a look at them.

Sign in to comment.

Categories

Find more on Graphics Performance in Help Center and File Exchange

Tags

Asked:

on 19 Jun 2011

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!