BUL Computer Tips for Matlab

Questions or suggestions about this page should be sent to mspisar@flip.eecs.umich.edu

Question index:

Q: How do I update from Matlab Version 4.x to 5.x
A: There are a number of changes in the new version of Matlab. The first thing to do is look at the help provided by Matlab. Try looking at How to Update Your Code, one section of the new Matlab Help Desk. The Help Desk can be reached from within Matlab by typing
>>helpdesk
Additionally, there is a Perl script to check some of the key changes in converting your .m files from Version 4 to 5. It is called /usr/coolstuff/matlab/mat4to5.pl and you can use it as follows:
% /usr/coolstuff/matlab/mat4to5.pl function.m
OR
% /usr/coolstuff/matlab/mat4to5.pl *.m > logfile.txt
Additionally, there are some command line switches to turn off some of the checks. Use:
-o to turn off looking for ones(A)
-e to turn off looking for eye(A)
-r to turn off looking for rand(A)
-z to turn off looking for zeros(A)
-s to turn off looking for strcmp or strncmp
-i to turn off looking for input(...,'s')
This script was copied from mat4to5.pl and slightly modified.
Other tips include: Q: How do I import Matlab figures into Microsoft Word on a PC?
A: Do the following:
  1. Print the figures from Matlab as EPS file using a command like: print -deps figure1.eps
  2. Run Word and move the insertion point to the position at which you want the figure
  3. Select the Insert..Picture menu option.
  4. List the "Encapsulated Postscript (*.eps)" type files, and select the figure you wish to insert.
  5. To keep the file size down and increase portability, it is recommended that you select "Link to File" and de-select "Save Picture in Document" options. This will, however, require that you keep both the document and all included .eps files in the same place, and when you move or copy the document you will need to move both the document and all included .eps files. However, this will make the document portable between the Mac and Windows versions of Word, and will only increase the file size slightly, since only a reference to the .eps file is stored in the document.
An alternative method is to copy the figure from Matlab, and paste it into Word as a Powerpoint object. The advantage of this is that you will be able to edit components of the figure such as line styles and font types and sizes using Powerpoint. To do this, do the following:
  1. Select Insert..Object from the menu, and select "Create New", "MS Powerpoint 4.0 Slide", and click on the OK button.
  2. Once in Powerpoint, resize the slide (using File..Slide Setup) to 12" by 8". (This will create a 6" by 4" figure in Word...don't ask me why.)
  3. Delete the title and sub-title from the slide.
  4. Following the procedure in How do I import Matlab figures into Powerpoint, cut the Matlab figure and paste it into the Powerpoint slide. It will appear blank.
  5. Drag/resize the figure until it fills the entire area of the slide.
  6. Double-click on the figure, and answer "Yes" to the prompt to convert the figure to Powerpoint objects.
  7. Click on an area away from the figure to de-select the objects.
  8. Click on a background area of the slide to select what appears to be the entire slide. Press <Delete> to delete this. At this point all of the other objects should appear.
  9. Select the "File..Update and Return" menu item, and answer "Yes" to the "Update Slide in Document" prompt.
Q: How do I import Matlab figures into Powerpoint on a PC?
A: You can cut them from Matlab in meta-file form, paste this into Powerpoint, and convert it to Powerpoint objects.
This is done as follows:
  1. In Matlab, type "system_dependent(14,'on') before creating the figure.
  2. Create the figure, and then maximize the figure window.
  3. Select the Edit..Copy Options menu item
  4. Select Windows Metafile as the clipboard format, de-select the "Honor figure sizes" option, and select the "Invert background" option.
  5. Select the Edit..Copy menu item. WAIT until you see the cursor flash and hour glass, or 15 seconds, whichever is shorter. You must wait for this to give the program time to copy the figure onto the clipboard.
  6. Switch to Powerpoint, and select the Edit..Paste menu item.
  7. Re-size the pasted item to fit where you want it.
  8. Double-click on the pasted item, and convert it to Powerpoint objects.
  9. Click once outside of the selected area.
  10. Click once on the black square, and then press <Delete> to delete the background object. The figure should now appear properly. You may select lines and text and change them as you would any Powerpoint object.

Alternatively, you can print the file in HPGL format, and use the HPGL import filter in Powerpoint.
This is done as follows:

  1. Print the figures from Matlab as an HPGL file using a command like:
    print -dhpgl figure1.hgl
    (note: use the extension .hgl with your file name)
  2. Run Powerpoint (or Word) and move to the page on which you want to place the figure
  3. Select the Insert..Picture menu option.
  4. List the "HP Graphic Language (*.hgl)" type files, and select the figure you wish to insert.
  5. In the options dialog box, de-select "Retain Background" and "Emulate Line Styles", and use "Normal" color translation. Then click on the OK button.
  6. Move and resize the figure to your liking.
  7. If you want to change the appearance of anything in the figure, double-click on it, and answer "Yes" to the convert-to-Powerpoint prompt. You can then select lines and text and modify them as you would any Powerpoint object.
Q: How do I import Matlab images from a Sun into PowerPoint?
A: Follow these steps:
  1. Create your image in the current matlab figure
    Note: If you are going to display the image on the Mac or make slides from the Mac slidemaker, make sure that the image has NO gamma correction (i.e., a gamma of 1.0). The Mac seems to do its own gamma correction.
  2. Save it in TIFF format:
    >> [x,map] = getframe(gcf);
    >> tiffwrite(x,map,<fname>.tiff);

    where <fname> is the desired filename.
  3. Load tiff image into PowerPoint.
Note: if resulting image is not the desired size, DONT scale it in powerpoint --it will look BAD! Go back to Matlab, and adjust the 'Position' attributes of the figure to resize it as desired, then save it again.

Q: How do I import Matlab plots from a Sun into PowerPoint?
A: There are a number of solutions:

  1. The best way, which does NOT use a bitmap, and retains each item as an object, is HPGL format (.hgl extension).
    In MATLAB, use
    >> print -dhpgl <fname>.hgl;
    where <fname> is the desired filename.
    When picture is inserted, scale as desired (e.g., 75%), THEN double click picture to separate into editable objects. You can then change line/text colors, line types, font size/style, text alignment, ...
    Note:
  2. A bitmaped (with less resolution) way is to save the plot as a TIFF file. The simplest way is to use the /vol/coolstuff/matlab command fig2tiff, e.g.,
    >> fig2tiff('<fname>.tiff');
    where <fname> is the desired filename.
    This will save the plot as a black and white image to put into PowerPoint. See the help on fig2tiff for more details.
Q: What is Tony's Trick?
A:Here's "Tony's trick," attributed to Tony Booer of Schlumberger:
To initialize a matrix with values "a" in the first row and values "b" in the second row, do the following:
[a(1,ones(1,m)) ; b(1,ones(1,m))]
Q: How do I get matab-mode in emacs?
A:Put the following in the .emacs file in your home directory:
;;; Add coolstuff elisp to search path
(if (file-directory-p "/usr/coolstuff/elisp")
(setq load-path (cons "/usr/coolstuff/elisp" load-path))
(message "Could not find /usr/coolstuff/elisp"))

;;; Matlab mode
(autoload 'matlab-mode "matlab" "Enter Matlab-mode." t)
(setq auto-mode-alist (cons '("\\.m$" . matlab-mode) auto-mode-alist))
(defun my-matlab-mode-hook ()
(setq fill-column 76)
(setq matlab-indent-end-before-return t)
(turn-on-auto-fill))
(setq matlab-mode-hook 'my-matlab-mode-hook)



Back to Internal Use Page