crop matlab plots
November 6, 2008 5:18 PM   Subscribe

How can I automatically crop the whitespace in Matlab plots pasted into Word?

I find a not insignificant portion of my time in report writing is spent cropping the extra whitespace around Matlab plots that are pasted into Word. Is there some way to eliminate the whitespace automatically, either with some nifty Word trick or by forcing Matlab to generate windows without so much whitespace around the plot? Thanks.
posted by pravit to Computers & Internet (6 answers total) 2 users marked this as a favorite
 
You could change the default page size that MATLAB uses for output to something more reasonable for your images. In MATLAB, printing and saving to file are pretty much the same thing, so when a figure is saved to file, it is effectively saved as if it was pasted onto an 8.5"x11" by default. You may want to use code generation to simplify repeating the process once you've got your figures sized correctly for cutting and pasting.

You might also want to consider using the Publish or Notebook features of MATLAB to do what you want.

Personally, for short reports Publish does everything I want.
posted by onalark at 7:26 PM on November 6, 2008


I'm reasonably sure that Matlab can export plots in various image formats. Set your scripts up to do that, then use ImageMagick on the command line to crop them all at once. (assuming the whitespace area is constant)

Something like :
convert -crop 200x100+300+400 plot.jpg plot_cropped.jpg
See also
posted by chrisamiller at 11:15 PM on November 6, 2008


Export from MATLAB as PDF; Acrobat has a Trim menu item that removes all whitespace. Many other graphics programs have similar.
posted by fatllama at 11:33 PM on November 6, 2008


I've never actually had this problem, which makes me wonder exactly what you are doing to cause it.

Can you describe how you move stuff from Matlab to Word?

I would do this:


> print -dpng figurename


And then drag the png into Word.
posted by dmd at 6:16 AM on November 7, 2008


Listen to fatllama. You're generating nice vector graphics - why are you dumping them as resolution-dependent images? Matlab will export them as vector, either PDF or postscript.

Also, don't just paste images into Word. Use the "Insert --> Image from File" command. Yes, it's slightly more of a pain, but it actually does something different than pasting does.
posted by caution live frogs at 6:43 AM on November 7, 2008


Response by poster: Can you describe how you move stuff from Matlab to Word?

In the plot window, I go to Edit->Copy Figure, then I paste it straight into Word. For what it's worth, it does convert it to vector graphics when I paste it, it just has this whitespace around it which makes it kind of difficult when I want to try to resize two plots to fit on the same page, for example.

Here's a screenshot of what I mean - notice the extra white space around the top and bottom of the plot.
posted by pravit at 9:46 PM on November 7, 2008


« Older Google pre-IPO annual reports?   |   Will CS4 run on a G4 Powerbook? Newer »
This thread is closed to new comments.