0

I am currently doing a project that requires the usage of the line function in Matlab. Lines are plotted using the line function on a graph. The code is something like this:

for i=0:N-1
    for j=0:N-1
        a = ...
        b = ...
        line(a,b,'...','.5')
    end
end

This is a part of a function and is called repeatedly. Thus multiple graphs such as these are created. Once I start executing the program, I want to automatically save these graphs as bitmap images. Is there any way to do that?

I tried using handles but wasn't very successful. The imsave function doesn't help since line doesn't return a matrix of the graph it produces. I looked into saveas, but couldn't get very far. Is there any way to do it?

horchler
  • 18,384
  • 4
  • 37
  • 73
mysticsasuke
  • 119
  • 1
  • 4
  • 12
  • It seems that your question is more about saving a figure than the line function itself, right? Maybe you could make your question more specific about that... There are quite some post around for that topic ([this](http://stackoverflow.com/questions/15984630/how-to-save-matlab-figure-as-jpeg-using-saveas-without-the-image-coming-off-ba?rq=1) or [this](http://stackoverflow.com/questions/12160184/how-to-save-a-figure-in-matlab-in-from-the-command-line)). You can also have a look at [`print`](http://www.mathworks.ch/ch/help/matlab/ref/print.html) - despite the name it can also save to a file. – mbschenkel Mar 13 '14 at 20:34
  • It is more about saving the figures. Since I am using calling the `line` repeatedly, the graph displays a large number of lines. I was able to save these graphs into .bmp files but there was quite a bit of drop in the picture quality. Thank you for the other links. They are quite helpful. – mysticsasuke Mar 14 '14 at 17:36

1 Answers1

2

The print function is for saving the contents of figures to bitmap images (or postscript or PDF). For instance,

print -dpng 'test.png'

will save the current figure as a png in the current directory. (See the documentation for additional tricks such as how to get it to appear the same size as on the screen, if that's what you want.)

Rex Kerr
  • 166,841
  • 26
  • 322
  • 407
  • 1
    `-dbmp` will give a bitmap image – David Mar 13 '14 at 21:20
  • @David - I figured the OP was using the generic term (bitmap image instead of vector graphics), not the old Windows default file format. But, yes, `-dbmp` will produce the Windows bitmap format. – Rex Kerr Mar 13 '14 at 21:21
  • Fair enough, just thought I'd mention it! To the OP though, consider using vector graphics (ep, for example `-depsc2`). Depending on what you are doing they can look far better than bitmap pictures. – David Mar 13 '14 at 21:26