any matlab gurus out there???

April 2, 2007 at 9:44 am | | everyday science, help me, software

I need some help with my Matlab m-file. Any geniuses know how to save a figure without the border?



  • The m-file produces an array of numbers: columns indicate the x- and rows the y-position of a pixel of intensity denoted by the number’s value
  • I make a figure and use the command pcolor
  • I turn the axis off
  • I save using the saveas command

Basically, I want the pcolor figure alone so I can import it into a different program and click on the image to move a stage to that location. Having a border means the stage will move to the wrong place. (I know this is a clunky solution to a scanning-stage program. Shut up. Stop making fun of me.)

Any thoughts? I’ve found that imwrite saves only the image array, but I don’t know how to use pcolor or shading 'interp' with imwrite.

To encourage random people to help me with my research, I’ll send an EDS magnet to the first person who tells me how to do this correctly—or at least points me in the right direction. I’ll update y’all as soon as I know.

[Update: Here’s a good image I created. See comments below.


I know, it’s flipped. But I can easily deal with that.

We have a winner, but I might send more magnets for more elegant solutions.]


RSS feed for comments on this post. TrackBack URI

  1. Are you importing just the image? I’d just crop it in another program, if matlab keeps being disagreeable.

    Comment by PhilipJ — April 2, 2007 #

  2. PhilipJ, thanks for the idea, but I’d rather not crop the image each time I take a confocal scan.

    Comment by sam — April 2, 2007 #

  3. A friend suggests that I “save it as text and then have your second program (labview?) recreate the figure from the text file for clicking purposes.”
    That may be what I end up doing. I’m only hesitant because I don’t really like Visual Basic, and that’s what the scanning program is written in. Matlab is way more fun!

    Comment by sam — April 2, 2007 #

  4. Since the figures would get output with the same dimension, it would be easy to use imagemagick to crop the same size every time.. but I agree that it isn’t a very nice solution.

    Comment by PhilipJ — April 2, 2007 #

  5. This is one way I figured out to make it work right.
    figure('Position',[1 1 300 300], 'PaperPositionMode', 'auto');
    imshow(pm,[], 'InitialMagnification', 'fit');
    colormap jet;
    print -djpeg matlabfigure;

    The same friend from the comment above helped, so she’ll get a magnet. Any other winners?
    BTW, I’m very aware that I’m going about this the long and complicated way. But I don’t care. Right now, I just want something that will work, if it’s clunky, so be it. Maybe someday I’ll take the time to write some pretty program, but … later.

    Comment by sam — April 2, 2007 #

  6. Hooray trackback spam? :)

    Comment by PhilipJ — April 3, 2007 #

  7. I removed the spam. Weird…

    Comment by sam — April 3, 2007 #

  8. These remind me of the lines I used to watch on TV early Saturday morning before the cartoons came on!

    Comment by jordan — April 5, 2007 #

  9. use “imview” command for the image and save it with jpeg ext.

    Comment by gourav kumar soni — December 19, 2008 #

  10. Hi , how did you make this exactly? I’m a student and i have to do the same thing take off the white borders of the axis.

    please if you can give me the code or any explanation about how save the image without borders i’ll be very happy.


    Comment by santi_po — April 14, 2009 #


    Comment by sam — April 14, 2009 #

  12. Try set(gca,’position’,[0 0 1 1])

    Comment by Tom — June 27, 2010 #

  13. try: box off

    Comment by Pat — July 15, 2010 #

Leave a comment

thanks for the comment

Powered by WordPress, Theme Based on "Pool" by Borja Fernandez
Entries and comments feeds. Valid XHTML and CSS.