quick question: I'm creating "random" polygons using either the patch() or the fill() function in Matlab. This works quite good and it is plotted correctly.
However, I need to at least save a few hundres polygons as images to my hard drive for working with them later - so 开发者_运维问答I'm looking for a way to directly save the image in my function rather than saving each polygon myself using the file-menu.
Is there any way to do this?
Thanks in advance!
You can indeed use the print
function, but I would not use the jpeg
device. JPEG is never the right format for plots (you will get a lot of artifacts near all your lines).
If you need a bitmap image, try the png
or tiff
device. If you don't need a bitmap, use the appropriate vector image format: fig
is the native MATLAB format (which allows you to edit the plot afterwards), so this is the best one if you stick with MATLAB for all your operations. For exporting to other software, I would recommend pdf
(works almost anywhere), epsc
(EPS with color, great for LaTeX or inkscape), wmf
/emf
(Windows Metafile, so Windows only, but great for including the images in MS Office). Or you could of course use any of the other formats mentioned in the print
documentation.
Sometimes it's a pain in the neck to get the format of your image all right (especially with PDF output). Just take a look at the different properties of your figure and more specifically the PaperSize
, PaperUnits
and PaperPosition
.
The easiest way, and I guess the best solution, is to save as a .fig
file. You can do this by using saveas
:
h = figure;
% your plot commands here
saveas(h,'mFile.fig');
Afterwards, you can reload the image with the openfig
function:
openfig('mFile.fig');
Have to add this answer. This function is helping a lot.
This function saves a figure or single axes to one or more vector and/or bitmap file formats, and/or outputs a rasterized version to the workspace, with the following properties: - Figure/axes reproduced as it appears on screen - Cropped/padded borders (optional) - Embedded fonts (pdf only) - Improved line and grid line styles - Anti-aliased graphics (bitmap formats) - Render images at native resolution (optional for bitmap formats) - Transparent background supported (pdf, eps, png) - Semi-transparent patch objects supported (png only) - RGB, CMYK or grayscale output (CMYK only with pdf, eps, tiff) - Variable image compression, including lossless (pdf, eps, jpg) - Optionally append to file (pdf, tiff) - Vector formats: pdf, eps - Bitmap formats: png, tiff, jpg, bmp, export to workspace
精彩评论