Showing posts with label eps. Show all posts
Showing posts with label eps. Show all posts

23/03/2012

Matlab figures in Powerpoint

I've just been putting together a presentation in which I wanted to include a set of Matlab plots. Whilst there are plenty of ways to do this I thought I would detail the way I managed it...

I've mentioned before about maintaining quality by using vector graphics. Previously I've used .eps format for this, but I don't think it's well supported in Powerpoint (I did consider using alternative presentation software but I was pressed for time and this seemed like the easiest option). Instead I used .emf format which seems pretty well supported by Matlab. This is a Windows specific format so I can't say I'm particularly keen on it for general use, but it served a purpose here.

I saved my figures as separate images from Matlab and then imported into Powerpoint, but I think the same result can be achieved if you simply copy and paste between the two.

One of the benefits of having the plots in vector format is the ability to manipulate them within Powerpoint itself. For the unscrupulous this could be a good technique for "adjusting" a few points here and there to improve  your results - but obviously I didn't do that! What I did do was separate out several lines that were on the same plot, so that I could make them appear (using Powerpoint's animation features) gradually. This made the plots (which were a comparison of the results of several different simulations) much cleaner.

It was a little bit of a hassle to do this, but not awful, and I think worthwhile as it made the results much easier to present. When the .emf file is initially imported it is handled as an image; however, if you right click on it you will find that it can be "ungrouped". You might have to repeat this process a few times as the image seems to be built up of several sub-groups, but once you're done you'll find that individual lines are available to be manipulated. Unfortunately I then had to go through and "regroup" some of them manually to reform complete lines, which involved a bit of 'Ctrl' clicking - this was the tedious bit. I guess it depends how complicated the lines in your plots are as to how long this will take (and whether it is worthwhile or not).

Another benefit was being able to alter the font of my axes to match my presentation style. A trivial point perhaps, but it all goes to improve the overall appearance.

So to summarise:

  1. Copy figure in Matlab
  2. Paste in Powerpoint
  3. Right click and "ungroup"
  4. Repeat 3. until you get to a  level that you can manipulate the objects that you want
  5. You may find there are a few large white squares that form the background of the plot - these can be deleted (it will make things easier when you come to regrouping things in step 7.)
  6. 'ctrl'+'a' to select everything and then change the font to match your presentation
  7. 'ctrl' and click on objects to collect all the ones that should be in a group (you may need to zoom in on your slides to do this accurately)
  8. right click and "group" them
  9. move/recolour/animate/resize the objects as you desire to suit your presentation!

Hope that is of help to someone!?

03/06/2011

Simulink to eps

I've mentioned previously that I've developed a process to export plots from Matlab and include them as (eps format) figures in a Latex document. Well today I spent a load of time trying to get a similar method working for exporting Simulink model diagrams from Matlab. This hasn't proved quite as easy, but I think I'm there now.

My main issue was that Simulink doesn't allow you to print in the same way as a normal Matlab figure does. The "print" command can be used, but it works in a very specific way. It is fairly easy to use this command to print in eps format (see my previous posting for why this is a good thing); however it doesn't allow you the same freedom to setup the page. More specifically it will only allow you to use a pre-defined page size (A4, US legal, etc). It rescales and centres the figure to fill the page, but, unless the model is the exact same aspect ratio as a pre-set paper type, you end up with white borders at either the top/bottom or left/right.

EDIT: This seems to have been corrected in newer versions of Matlab now!

I've tried all sorts to get round this, including calling Ghostscript from within matlab to post-process the eps file. This should work as it ought to be able to find the right "bounding-box" for the figure and resize the page accordingly. However I had no luck with this - it would either not trim it down at all, or over-trim it removing some of the image.

I also tried exporting in a few other formats (namely normal postscript and pdf) and then converting with Ghostscript. This worked a little better and I was able to get the right bounding box through a process of:
  1. Simulink export to pdf, 
  2. Ghostscript convert pdf-to-eps, 
  3. Ghostscript convert eps-to-eps. 
I have no idea why that last step was necessary! Unfortunately although the output from this was pretty good, the text becomes part of the image (I think during the second step), meaning it doesn't render properly at high zoom levels. I don't know why that happened, I'm pretty sure it shouldn't have, but I thought I could do better.

So an alternative process I finally came up with is:
  1. Find out the ratio of the figure (I did this by exporting as a raster image and then reading back in - I'm not very happy with this technique as it's pretty dirty, but at least it works)
  2. Simulink export to eps, with the model at the very bottom of the page
  3. Automatically edit the resulting eps file to adjust its bounding box information
It's a bit hacky, and if I was being picky the margins aren't perfectly even in the resulting file, but it seems to work. I'm sure there must also be a better way of achieving step 1, but it's sufficient for now. (If anyone has any suggestions then I'd love to hear them!?)

There's nothing very clever in the code, but if anyone wants a copy of my function I'll happily forward it to them. Hope this helps somebody!

EDIT: Code for my function is available here.