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:
- Simulink export to pdf,
- Ghostscript convert pdf-to-eps,
- Ghostscript convert eps-to-eps.
So an alternative process I finally came up with is:
- 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)
- Simulink export to eps, with the model at the very bottom of the page
- Automatically edit the resulting eps file to adjust its bounding box information
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.
I have been hacking/screwing around lately in order to to get a lot of simulink schematics displayed in LaTex. It would be awesome if you could send me a copy of the function you use!
ReplyDeleteSeppe
Seppe, I've put my function here. Like I say it's not a perfect solution, but I think it should work better than the alternatives. If you come up with any better approaches or improvements then please let me know!
ReplyDeleteThanks, It seems to work rather well.. I changed the width/height multiplier constant to 0.6 instead of 0.99, this way the models can be fully displayed on A4 in portrait mode...
ReplyDeleteTomorrow I'll hopefully get some more info from a professor at my school who told me something about editing settings that define the default size of a model, I'll keep you updated if I find a more elegant solution.
Hello there welf,
ReplyDeleteJust came across some solutions and found one to have nice results.
The "print" command can actually export the model to a vector eps, as seen here: http://locksley90.blogspot.com.br/2008/11/exporting-simulink-models-to-eps-or.html
Hope it helps you and your readers... Helped me for sure! =]
PS.: The command on the URL will convert only the main model. If you, like me, pefers to organize the model in subsystems, just add "/subsystemname" to the model name on the print command and it will convert just the desired one. Borrowing the example:
print -ssimmodel/yoursubsystemname -deps -r300 simmodel.eps
Greetings from Brazil.
Hi there,
ReplyDeleteThis is the exact method that I used, however I also included some extra steps to reduce the size of the final images (otherwise it comes out with very large margins).
I've just retested in a newer version of Simulink (r2012a) and it seems that the extra steps are no longer necessary. I guess they must have improved/corrected the way the bounding box was calculated.
Thanks for prompting me to check this!