You are on page 1of 60

MATLAB FREQUENTLY-ASKED QUESTIONS

Frequently Asked Questions maintained by Michele Zavada (michelez@mathworks.com)

Table of Contents:
y

1.General Questions o 1.1.General Information  1.1.1.What is MATLAB?  1.1.2.What is SIMULINK?  1.1.3.On what machines is MATLAB available?  1.1.4.What was first: the company MathWorks or the product MATLAB?  1.1.5.What is the history of MATLAB?  1.1.6.What is the charter for the USENET Newsgroup comp.softsys.matlab?  1.1.7.Are there any software archives?  1.1.8.Are there any publications related to MATLAB?  1.1.9.What toolboxes are currently available from The MathWorks?  1.1.10.How do I contact The MathWorks about MATLAB via email? o 1.2.Product Information  1.2.1.What's new in MATLAB 4.2?  1.2.2.When will MATLAB 4.2 be released on the various platforms?  1.2.3.How does MATLAB perform on machine X?  1.2.4.What's new with SIMULINK?  1.2.5.What's new in Signal Processing Toolbox version 3.0?  1.2.6.What's new in Neural Network Toolbox version 2.0?  1.2.7.Can a C or FORTRAN subroutine be called directly from MATLAB?  1.2.8.Can I call MATLAB routines from my C or FORTRAN programs?  1.2.9.Is there going to be a 4.0 version of the Student Edition?  1.2.10.Is there a MATLAB compiler? o 1.3.User Questions  1.3.1.General MATLAB Questions  1.3.1.1.How do I import graphics into other applications?  1.3.1.2.How do I run MATLAB in the background under UNIX? MS Windows?  1.3.1.3.Why doesn't MATLAB run as fast as I expect it to?

1.3.1.4.How can I change the default window size, colors, etc., in MATLAB?  1.3.1.5.How do I manipulate colormaps?  1.3.1.6.Is there a topical help function, like 'apropos'?  1.3.1.7.How can I get information about undocumented functions (like comet) in MATLAB?  1.3.1.8.How does the Random generator work?  1.3.1.9.Is there a Pseudo-Random Binary Sequence (PRBS) generator in MATLAB?  1.3.1.10.What is the numeric precision of MATLAB?  1.3.1.11.How do I run MATLAB in batch mode? 1.3.2.Matrices  1.3.2.1.What is the largest matrix MATLAB can handle?  1.3.2.2.How does MATLAB index its matrices?  1.3.2.3.Can MATLAB handle multidimensional arrays?  1.3.2.4.How can I initialize a low rank matrix easily? 1.3.3.Functions  1.3.3.1.Why, when I edit a function file in MATLAB, is the change not seen by MATLAB until everything is cleared or MATLAB is restarted?  1.3.3.2.How can I get the parser to accept a dummy reference without an error?  1.3.3.3.Is there a GNU emacs editing mode for MATLAB?  1.3.3.4.Does MATLAB have a debugger? 1.3.4.eval Command  1.3.4.1.How does the eval command work?  1.3.4.2.How can I use a filename that is a variable as an input argument to the load, save, and print functions? 1.3.5.MATLAB Functions  1.3.5.1.Why was fsolve removed from MATLAB Version 4?  1.3.5.2.What is griddata? How do I use it to contour irregularly spaced data?  1.3.5.3.What is the sign convention used in MATLAB's fft routines?  1.3.5.4.How do I fit a curve in MATLAB? 1.3.6.File I/O  1.3.6.1.How do I use fread, fwrite, and fprintf?  1.3.6.2.How can I store the result of ls *.dat in a variable? 1.3.7.Differential Equations  1.3.7.1.Can MATLAB solve Ordinary Differential Equations (ODE)?  1.3.7.2.How do I pass in extra parameters to ode and quad?  1.3.7.3.How do I do double integration in MATLAB? 1.3.8.Memory  1.3.8.1.What can I do when MATLAB tells me I'm out of memory?


1.3.9.Student Edition  1.3.9.1.Why does my Student Edition hang my machine after the MATLAB banner is displayed?  1.3.9.2.How do I print using the Student Edition?

2.Graphics o 2.1.Using get and set  2.1.1.What is a handle?  2.1.2.How do I use get and set?  2.1.3.What properties can I control?  2.1.4.How do I change the default settings for an object's properties?  2.1.5.How do I change the default settings back to their original settings? o 2.2.Properties of the Figure and the Axes  2.2.1.Fonts  2.2.1.1.How do I change the font of text objects?  2.2.1.2.How do I change the font of tick labels?  2.2.1.3.How do I get Greek letters in my text objects?  2.2.1.4.Can I have multiple fonts in one text object?  2.2.2.Lines  2.2.2.1.How do I change the line width?  2.2.2.2.How do I change the line style order on printouts?  2.2.2.3.How do I cycle through the line color order?  2.2.3.Positions  2.2.3.1.How do I change the size and position of my figure window?  2.2.3.2.How do I define an invisible axis?  2.2.3.3.Which units should I use? o 2.3.Background Color  2.3.1.How do I invert the background on my printout?  2.3.2.How do I change my background for plots? o 2.4.Using MATLAB Graphs with Other Packages  2.4.1.Can graphics be saved as files to be imported back into MATLAB for viewing and alteration?  2.4.2.Can I edit MATLAB graphs in other applications?  2.4.3.How do I copy and paste MATLAB graphs to the clipboard? o 2.5.Graphical User Interface (GUI)  2.5.1.How do I make a dialog box?  2.5.2.How do CallBacks work? What is the best way to write a CallBack?  2.5.3.Where do CallBacks get executed? o 2.6.Miscellaneous  2.6.1.Why does waterfall return a blank screen?  2.6.2.How do you get perspective with 3-D plots?  2.6.3.Why does MATLAB sometimes draw patches out of order?  2.6.4.How do I use multiple colormaps?  2.6.5.What is the difference between pcolor and image? 3.Printing o 3.1.General

3.1.1.How do I print in MATLAB? 3.1.2.How do I print a SIMULINK block diagram? o 3.2.GhostScript  3.2.1.What is GhostScript? How do I use it?  3.2.2.Where can I get documentation for GhostScript?  3.2.3.Why would I print with a GhostScript device?  3.2.4.What do I do if my printer isn't listed among the GhostScript devices?  3.2.5.How do you use GhostScript to display PostScript files to the screen from DOS? o 3.3.Printing to a File  3.3.1.How do I print to a file?  3.3.2.How do I know what option to use?  3.3.3.How do I print out an HPGL format file? o 3.4.SIMULINK Printing  3.4.1.How do I change fonts in SIMULINK?  3.4.2.What do I do if I am getting SIMULINK blocks and no text?  3.4.3.How do I print my SIMULINK diagram on more than one page?  3.4.4.How do I print a SIMULINK model from within an M-file? o 3.5.Common Problems  3.5.1.Why does my printer hang when I try to print from the pulldown menu?  3.5.2.Why, after a long session of MATLAB under MS Windows where many figures printed, do I start to have a problem printing?  3.5.3.Why don't my axis labels print correctly?  3.5.4.Why can't I print broken lines?  3.5.5.Why can't I print UI controls?  3.5.6.Why, when I use interpolated shading or print surfaces, does my graph look "blocky" when the graph looked fine on the screen?  3.5.7.What do I do if my PC beeps and hangs when I try to print? 4.License Manager o 4.1.Installing MATLAB  4.1.1.Are there step by step instructions for installation?  4.1.2.When should I run lmdebug?  4.1.3.When do I have to run the license manager? o 4.2.License Configurations  4.2.1.How do I set up the license manager so that it runs on a heterogeneous network?  4.2.2.On a UNIX network, how do I run a back-up server configuration?  4.2.3.How do I combine license.dat files if I am running another vendor that uses FlexLM?  4.2.4.How do I run two versions of MATLAB on a VAX? o 4.3.Common Error Messages:  4.3.1.Cannot Connect to License Server  4.3.2.XXX Feature is not Currently Licensed  4.3.3.Environment Variable of lm_license_file Not Defined
 

4.3.4.No TCP License Server Exists 4.3.5.Invalid Returned Data From License Server 4.3.6.License Server Does Not Support This Feature 4.3.7.Unable to Read License File 5.SIMULINK/MEX-Files/Engine o 5.1.SIMULINK  5.1.1.Printing SIMULINK models  5.1.1.1.How do I print my SIMULINK model?  5.1.1.2.Why doesn't the text on my SIMULINK diagram print out?  5.1.2.MATLAB Function block  5.1.2.1.Why can't I call any MATLAB function from the MATLAB Function block?  5.1.2.2.What is the difference between the MATLAB Function block and the function block?  5.1.3.General Questions  5.1.3.1.How do I mask SIMULINK blocks?  5.1.3.2.Why doesn't linmod return the correct results?  5.1.3.3.Can SIMULINK handle complex signals?  5.1.3.4.How do I use the set_param and get_param functions?  5.1.4.S-functions  5.1.4.1.What is the flag ordering for S-functions?  5.1.4.2.How do I display values numerically, rather than graphically (with the scope)?  5.1.4.3.Are there any examples of S-functions in C? FORTRAN? o 5.2.MEX-Files and Engine  5.2.1.Compilers we support  5.2.2.MEX-File function examples  5.2.2.1.Where can I get C MEX-file function examples?  5.2.2.2.Are there any FORTRAN MEX-file examples?  5.2.2.3.How do I write a C++ MEX-file function?  5.2.2.4.Are there any engine examples?  5.2.3.Common Problems  5.2.3.1.Why an I getting a segmentation violation error?
   

1. General Questions
1.1. General Information
1.1.1. What is MATLAB?
MATLAB was originally developed to be a "matrix laboratory," written to provide easy access to matrix software developed by the LINPACK and EISPACK projects. Since then, the software has evolved into an interactive system and programming language for general scientific and

technical computation and visualization. The basic MATLAB data element is a matrix. MATLAB commands are expressed in a form very similar to that used in mathematics and engineering. For instance, b = A x, where A, b, and x are matrices, is written b = A * x . To solve for x in terms of A and b, write x = A\b . There is no need to program matrix operations explicitly like multiplication or inversion. Solving problems in MATLAB is, therefore, generally much quicker than programming in a high-level language such as C or FORTRAN. There are hundreds of built-in functions that come with the basic MATLAB and there are optional "toolboxes" of functions for specific purposes such as Controls, Signal Processing, and Optimization. Most of the functions in MATLAB and the Toolboxes are written in the MATLAB language and the source code is readable. There are two basic versions of the software, the professional version, and the student edition. The student edition is distributed by Prentice-Hall, the professional version is distributed by The MathWorks, Inc. Send an email to info@mathworks.com or call 508-65-pi (508-653-1415) for more information.

1.1.2. What is SIMULINK?


SIMULINK is an interactive system for the nonlinear simulation of dynamic systems. It is a graphical, mouse-driven program that allows systems to be modeled by drawing a block diagram on the screen. It can handle linear, nonlinear, continuous-time, discrete-time, multivariable, and multirate systems. SIMULINK runs on workstations using X-Windows, under Microsoft Windows on the PC, and on the Macintosh. It takes full advantage of windowing technology, including pull-down windows and mouse interactions. SIMULINK is fully integrated with MATLAB, and, together with MATLAB and the Control System Toolbox, forms a complete control system design and analysis environment.

1.1.3. On what machines is MATLAB available?


MATLAB is available on machines ranging from the PC to the Cray. The list includes PC, Macintosh, and NEC personal computers, Sun, DEC, HP, IBM, and SGI workstations, VAX minicomputers, and Convex and Cray supercomputers.

1.1.4. What was first: the company MathWorks or the product MATLAB?
MATLAB was first. The MathWorks, Inc. was founded in 1984 to develop and market MATLAB.

1.1.5. What is the history of MATLAB


In the mid-1970s, Cleve Moler and several colleagues developed the FORTRAN subroutine libraries called LINPACK and EISPACK under a grant from the National Science Foundation. LINPACK is a collection of FORTRAN subroutines for solving linear equations, while EISPACK contains subroutines for solving eigenvalue problems. Together, LINPACK and EISPACK represent the state of the art software for matrix computation. In the late 1970s, Cleve, who was then chairman of the computer science department at the University of New Mexico,

wanted to be able to teach students in his linear algebra courses using the LINPACK and EISPACK software. However, he didn't want them to have to program in FORTRAN, because this wasn't the purpose of the course. So, as a "hobby" on his own time, he started to write a program that would provide simple interactive access to LINPACK and EISPACK. He named his program MATLAB, for MATrix LABoratory. Over the next several years, when Cleve would visit another university to give a talk, or as a visiting professor, he would end up by leaving a copy of his MATLAB on the university machines. Within a year or two, MATLAB started to catch on by word of mouth within the applied math community as a "cult" phenomena.

1.1.6. What is the USENET Newsgroup comp.soft-sys.matlab ?


The newsgroup comp.soft-sys.matlab is a forum for discussing issues related to the use of MATLAB, the scientific calculation and visualization package from The MathWorks Inc. Appropriate discussion in the group will include both general MATLAB issues and platformspecific questions, and discussions comparing MATLAB to other systems.

1.1.7. Are there any software archives?


The MathWorks maintains an archive on the anonymous ftp server ftp.mathworks.com [144.212.100.10]. This site contains a "best of" copy of the NETLIB archive as well as other user-contributed, and MathWorks-contributed software and documentation. If you are interested in submitting software to the archive, get the file /README.incoming on the ftp site or send email to: drea@mathworks.com.

1.1.8. Are there any publications related to MATLAB?


Yes, The MathWorks Inc. publishes a quarterly newsletter that gives information on products (new versions, releases, toolboxes), the MATLAB user group, MATLAB short courses, related texts etc. There is also a monthly email digest that contains annoncements, Q &A requests from users, news about our Internet services, etc. To subscribe to the newsletter, send email to subscribe@mathworks.com (Be sure to include your address adn your site identification/license number. To find out your site id, type "ver" at the MATLAB prompt.), or just type subscribe at your MATLAB prompt.

1.1.9. What toolboxes are currently available from The MathWorks?


Control System Toolbox : This is a toolbox for control system design and analysis. It supports transfer function and state-space forms (continuous/discrete time, frequency domain), as well as functions for step, impulse, and arbitrary input responses. Functions for Bode, Nyquist, Nichols plots, design with root-locus, pole-placement, and LQR optimal control are also included. Image Processing Toolbox : The Image Processing Toolbox builds on MATLAB's numeric, signal processing, and visualization capabilities to provide a comprehensive system for image processing and algorithm development.

MMLE3 Identification Toolbox : The MMLE3 Identification Toolbox is a specialized toolbox for use with MATLAB and the Control System Toolbox for the estimation of continuous-time state-space models from observed input-output data. Model Predictive Control Toolbox : The Model Predictive Control Toolbox is especially useful for applications involving constraints on the manipulated and/or controlled variables. For unconstrained problems, model predictive control is closely related to linear quadratic optimal control, but includes modeling and tuning options that simplify the design procedure. Mu-Analysis and Synthesis Toolbox : The Mu-Analysis and Synthesis Toolbox contains specialized tools for the analysis and design of robust, linear control systems, extending MATLAB to provide additional application-specific capabilities. Nonlinear Control Design : This toolbox provides a Graphical User Interface to assist in timedomain-based control design. With this toolbox, you can tune parameters within a nonlinear SIMULINK model to meet time-domain performance requirements. You can view the progress of an optimization while it is running. Optimization routines have been taken from the Optimization Toolbox. Neural Network Toolbox : This is a toolbox for designing and simulating neural networks and supports implementation of the perceptron learning rule, the Widrow-Hoff rule, and several variations of the backpropagation rule. Transfer functions included are hard limit, linear, logistic, and hypertangent sigmoid. Optimization Toolbox : This is a toolbox for linear and nonlinear optimization. It supports unconstrained and constrained minimization, minimax, nonlinear least squares, multi-objective, semi-infinite optimization, linear programming, quadratic programming, and the solution of nonlinear equations. Robust Control Toolbox : This is a toolbox for robust control system design and supports LQG/loop transfer recovery, H2, H0, and mu- control synthesis, singular value frequency response, and model reduction. Signal Processing Toolbox : This is a toolbox for digital signal processing (time series analysis). It includes functions for the design and analysis of digital filters, like Butterworth, Elliptic, and Parks-McClellan, and for FFT analysis (power spectrum estimation). It also includes some two-dimensional signal processing capabilities. Spline Toolbox : This is a toolbox for working with splines and is typically used for curve fitting, solution of function equations, and functional approximation. Statistics Toolbox : The Statistics Toolbox builds on the computational and graphics capabilities of MATLAB to provide: 1) statistical data analysis, modeling, and Monte Carlo simulation 2) building blocks for creating your own special-purpose statistical tools, and 3) GUI tools for exploring fundamental concepts in statistics and probability.

Symbolic Math Toolbox : The Symbolic Math Toolbox contains functions for symbolic algebra, exact linear algebra, variable precision arithmetic, equation solving, and special mathematical functions. Its underlying computational engine is the kernel of Maple. The Extended Symbolic Math Toolbox augments the functionality to include Maple programming features and specialized libraries. System Identification Toolbox : This is a toolbox for parametric modeling. Identified models are in transfer function form (either z transform or Laplace transform) and state-space form (e.g., ARMA models or Box-Jenkins models). Chemometrics Toolbox : This toolbox contains a library of functions that allows you to analyze data based on chemometrics methods including multiple linear regression, classical least squares, inverse least squares, Q-matrix, factor based methods, principle component regression, and partial least squares in latent variables. There are also useful functions for plotting data. Frequency Domain System Identification Toolbox : This toolbox contains specialized tools for identifying linear dynamic systems from measurements of the system's excitation and response. Some of the identification procedures include excitation signal design, parameter estimation, graphical presentation of results, and model verification. Hi-Spec [tm] Toolbox : The Hi-Spec [tm ] Toolbox, a Partner Series Toolbox, was created by Jerry Mendel, C.L. (Max) Nikias, and Ananthram Swami. The Hi-Spec Toolbox is a collection of MATLAB routines whose primary features are functions for: 1. 2. 3. 4. 5. Higher-order spectrum estimation either by conventional or parametric approaches Magnitude and phase retrieval Adaptive linear prediction Harmonic retrieval and quadratic phase coupling Time-delay estimation and array signal processing

Toolkits are also available from The Mathworks, Inc. Toolkits are colections of M-files associated with books. These are available from the publisher or from ftp.mathworks.com in /pub/books . Control of Spacecraft and Aircraft Toolkit : This is a package of MATLAB programs to demonstrate the concepts discussed in the text "Control of Spacecraft and Aircraft," by Arthur E. Bryson. (1994) Princeton University Press, 1994. Signal Processing Examples Toolkit : This is a package of MATLAB programs to demonstrate the concepts discussed in the text "Computer-Based Exercises for Signal Processing Using MATLAB," by C. Sidney Burrus, James H. McClellan, Alan V. Oppenheim, Thomas W. Parks, Ronald W. Schafe, and Hans Schuessler. (1994) Prentice Hall. Delta Toolkit : This is a toolkit for analysis using the delta transform, an approach to unifying continuous and discrete systems theory without use of the z transform. It is available free to

purchasers of "Digital Control and Estimation: A Unified Approach," by Graham Goodwin and Rick Middleton. Numerical Methods for Physics Toolkit : This is a toolkit for which demonstrates the concepts discussed in the text "Numerical Methods for Physics Using MATLAB," by Alejandro Garcia. (1994) Prentice Hall. It is available free to purchasers of this text. Numerical Methods for Mathematics, Science and Engineering Toolkit : This is a toolkit for which demonstrates the concepts discussed in the text "Numerical Methods for Mathematics, Science and Engineering, Second Edition," by John H. Matthews. (1994) Prentice Hall. It is available free to purchasers of this text. Introduction to Linear Algebra Toolkit : This is a package of MATLAB programs to use with MATLAB in learning and experimenting with linear algebra. The toolbox is coordinated with the text: "Introduction to Linear Algebra," by Gilbert Strang. (1993) Wellesley-Cambridge Press Box 812060 Wellesley MA 02181. Templates Toolkit. The M-files were created to supplement "Templates for the Solution of Linear Systems: Building Blocks for Iterative Methods," by Richard Barrett, Michael Berry, Tony Chan, James Demmel, June Donato, Jack Dongarra, Victor Eijkhout, Roldan Pozo, Charles Romine, and Henk van der Vorst (SIAM, 1994).

1.1.10. How do I contact The MathWorks about MATLAB via email?


Here you go ... * support@mathworks.com Technical support * suggest@mathworks.com Product enhancement suggestions * bugs@mathworks.com Bug reports * doc@mathworks.com Documentation error reports * subscribe@mathworks.com Subscribing user registration * service@mathworks.com Order status, renewals, passcodes * info@mathworks.com Sales, pricing, general info. * digest@mathworks.com Submission and questions for the digest

1.2.Product Information
1.2.1.What's new in MATLAB 4.2?

Here's a summary of the major additions and changes: * Ability to produce hpgl format files * Ability to import graphs into Adobe Illustrator '88 * Ability to save a figure and load it back into MATLAB * Better, faster graphics * DDE capability for the PC * Online documentation for UNIX systems * International Character Support (limited) * Many memory leak fixes

1.2.2. When will MATLAB 4.2 be released on the various platforms?


The PC, SunOS, Solaris 2.2 and 2.3 and HP700 versions were released in late April 1994. Other UNIX platforms and the VMS version will follow shortly. In late May, the Mac version came out. The version for Power PC for the Mac will be released in late 1994.

1.2.3. How does MATLAB perform on machine X?


One way to measure the speed of MATLAB is by looking at the LINPACK benchmarks: One way to measure the speed of MATLAB is by looking at the LINPACK benchmarks: PC performance range: LINPACK (KFLOPS) VAXstation 3100 (VMS/D_floating) 365 HP 9000/400 (68030) 500 80486-based PC (33M Hz) 1300 HP 9000/425 (68040 chip) 1400 Macintosh Quadra 700 1500 Sun SPARCstation 1 1500 DECstation 3100 1600

SGI Indigo 2400 Sun SPARCstation 2 3600 Sun SPARCstation 10 9500 Convex C1 3700 IBM RS/6000 7000 HP 9000/700 7400 Cray X-MP 71000 Cray X-MP on a 500-by-500 matrix 135000

1.2.4.What's new with SIMULINK?


SIMULINK has added the following features in version 1.3: * Vectorization of blocks * Scalar expansion of inputs * Automatic routing of block connections * Wide vector lines * Sample time coloration of model * Enhanced S-functions * Many bew blocks!

1.2.5.What's new in Signal Processing Toolbox version 3.0?


The toolbox now offers enhanced filter design tools for digital and analog filters. Capabilities include the design of optimal least-square filters, minimum order estimation for FIR filters designed with remez , support for cascade filter implementation (second order sections decomposition), and analog Bessel filters. The toolbox has new functions to compute parametric models of signals and linear systems. In addition, there are now graphical demonstrations to provide easy exploration of filter parameters.

1.2.6.What's new in Neural Network Toolbox version 2.0?

Some significant improvements include the addition of trainlm , the Levenberg-Marquardt training algorithm, radial basis functions for the efficient design of supervised feedforward networks, and the recurrent Elman network, which allows you to create networks that can both recognize and generate temporal patterns.

1.2.7.Can a C or FORTRAN subroutine be called directly from MATLAB?


Yes, using "MEX-files." MATLAB's MEX-file facility allows any C or FORTRAN subroutine to be called directly from MATLAB. The MEX-file facility dynamically links your C or FORTRAN subroutine to the MATLAB program at run time.

1.2.8.Can I call MATLAB routines from my C or FORTRAN programs?


Yes, there are two ways. The first is using "MEX-files." MATLAB's MEX-file facility allows any C or FORTRAN subroutine to be called directly from MATLAB. The MEX facility dynamically links your C or FORTRAN subroutine to the MATLAB program at runtime. From inside your C or FORTRAN subroutine, you can then call any MATLAB function. To call a MATLAB function from your program, you start MATLAB, then call your program. Your program is then in control and can access any MATLAB function. The second way to call MATLAB routines from your program is to use MATLAB as a computational engine. A set of subroutines is provided that allows you to start MATLAB, send data and commands to it, get data back, and terminate MATLAB. This way you can call any MATLAB routine from your FORTRAN or C function.

1.2.9.Is there going to be a 4.0 version of the Student Edition?


A Student Edition of MATLAB 4.0 is currently in development. This new version will be released in the early Fall of 1994.

1.2.10.Is there a MATLAB compiler?


A MATLAB compiler is currently in development. The release date is to be determined.

1.3.User Questions
1.3.1.General MATLAB Questions
1.3.1.1.How do I import graphics into other applications? The MATLAB (version 4) print command provides a -deps argument which provides an Encapsulated PostScript file of your plot. Some people have reported various problems getting this to work. Some suggestions: Removing the last line %%EOF from the eps-file.

Use the pstoepsi filter from Doug Crabill ( dgc@cs.purdue.edu ). Use bbps and GhostScript. bbps.shar is available via anonymous ftp on csi.jpl.nasa.gov . You'll need to get GhostScript from your nearest GNU ftp site. Also, there is a technical note written on this topic available on our anonymous ftp server. It can be found in pub/tech-support/tech-notes/mat4.txt . 1.3.1.2.How do I run MATLAB in the background under UNIX? MS Windows? In UNIX: The nohup command and unsetting the display will allow you to run MATLAB in the background successfully even when you logout. Try the following:
set OLDDISPLAY=$DISPLAY unsetenv DISPLAY nohup matlab < filein > fileout & setenv DISPLAY $OLDDISPLAY

where filein is the M-file you want to run and fileout is the file you want the output to go to. To set this up as a C shell script, write a file called matbat as:
#!/bin/csh set OLDDISPLAY=$DISPLAY unsetenv DISPLAY nohup matlab < $1 > $2 & setenv DISPLAY $OLDDISPLAY

To run this file, issue the command as:


matbat infile outfile

In MS Windows: You need to set the ratio for applications running in the foreground as opposed to running in the background. This ratio will determine how well you can run MATLAB in the background. To set this ratio, go into 386 Enhanced in your Windows Control Panel. You can change your ratio here. 1.3.1.3.Why doesn't MATLAB run as fast as I expect it to? There are several things that can make MATLAB run slowly. FOR loops take a long time to run in MATLAB (relatively). You should avoid using them if at all possible, or have your for loops run in MEX-files. If you are using scripts rather than functions, then MATLAB loads your script into memory one line at a time, every time you call it. Functions are compiled into pseudo-code

and are loaded into memory the first time they are called. Subsequent calls to the function are executed more quickly. Make sure that you don't have any other large applications running in the background and that there aren't a lot of other people logged onto your machine. These things can also cause MATLAB to run slowly. 1.3.1.4. How can I change the default window size, colors, etc., in MATLAB ? From gray@SCR.slb.com ... If you're running MATLAB 4.x, something like the following should appear in your startup.m file:
set(0,'DefaultFigurePosition',[5,5,505,405]) set(0,'DefaultFigureColor',[0,0,0]) %%N.B this has side %%effects. set(0,'DefaultAxesFontName','times') set(0,'DefaultTextFontName','times') set(0,'DefaultAxesFontSize',12) set(0,'DefaultTextFontSize',12)

or from Brian Fitzgerald < fitzgb@mml0.meche.rpi.edu > ...


figure(1) set(1,'Position', [ 10 10 610 610])

1.3.1.5. How do I manipulate colormaps? When you use a function that calls a colormap, the function assigns values in the matrix to certain values in the default colormap. The lowest value in your matrix is assigned to the first color in your colormap. There is a colormap command in MATLAB, which allows you to set your colormap to 10 different sets of colors. For example,
colormap cool

gives you shades of cyan and magenta while


colormap jet

gives you shades of blue.

You can set a limit on your colors using the functions caxis, cmin, and cmax. These functions let you define the range of colors you will be using. 1.3.1.6. Is there a topical help function, like 'apropos'? Yes. The function you're looking for is lookfor (in MATLAB 4).
>> lookfor fourier FFT FFT2 IFFT IFFT2 Discrete Fourier transform. Two-dimensional Fast Fourier Transform. Inverse discrete Fourier transform. Two-dimensional inverse discrete Fourier transform.

FOURIER Graphics demo of Fourier series expansion. DFTMTX Discrete Fourier transform matrix.

1.3.1.7. How can I get information about undocumented functions (like comet) in MATLAB? Most things in the /demos directory are not described in the MATLAB User's Guide. There are lots of goodies there. In 4.0, the demos are the best place to see examples of Handle Graphics. There are other undocumented functions in directories other than /demos. Some of them are "worker" functions that are unlikely to be used directly; they are simply called by other functions. A few, like comet and comet3, were written after the MATLAB User's Guide was sent to the printer. 1.3.1.8. How does the Random generator work? The algorithm for the rand function can be found in S. K. Park and K. W. Miller, "Random Number Generators : Good ones are hard to find," Comm. ACM, vol. 32, n. 10, Oct. 1988, pg 1192-1201. The formula used for the seed is:
seed=(7^5*seed)mod(2^31-1)

If you want to set the initial seed to an random value, type the following at the MATLAB prompt:
rand('SEED',fix(100*sum(clock)))

This will use the clock to set the seed. 1.3.1.9. Is there a Pseudo-Random Binary Sequence (PRBS) generator in MATLAB ?

There is a PRBS generating M-file in the new Frequency Domain System Identification Toolbox, for lengths 2^2-1 to 2^30-1. Its name is mlbs (for Maximum Length Binary Sequence). 1.3.1.10. What is the numeric precision of MATLAB? In MATLAB, numeric quantities are represented as double precision floating point numbers. On most computers, such numbers have 53 significant binary bits, which is about 15 or 16 decimal digits. 1.3.1.11. How do I run MATLAB in batch mode? Here is an example of how to run MATLAB in batch mode from your UNIX prompt: Bourne shell example: (file called atfile.sh )
TERM=; export TERM matlab > inline.out << EOF a = [1 2] quit EOF

Sample at command on Sun: (-s says use the Bourne shell)


% at -s now + 1 min atfile.sh

C shell example: (file called atfile.csh )


setenv TERM matlab >! inline.out << EOF a = [1 2] quit EOF

Sample at command on Sun:


% setenv SHELL '/bin/csh -f' % at now + 1 min atfile.csh % setenv SHELL /bin/csh

In summary, Define TERM in the script before you call MATLAB and make it part of the environment. Be sure that the right shell is used to execute the script. If your script is a C shell, you must do the SHELL change in order not to get any extra mail messages from the job. Remember that -f means that your .cshrc file will not be executed before you run the script. So, you cannot use any of the parameters set in the script.

1.3.2. Matrices
1.3.2.1. What is the largest matrix MATLAB can handle ? MATLAB itself has no limits on matrix or vector sizes. There are no fixed-size arrays dimensioned within the MATLAB program. MATLAB uses the dynamic memory allocation and virtual memory facilities provided by most operating systems to obtain its memory. Any limits on memory and hence matrix size are those imposed by the operating system or the hardware. On most computers, these limits can be set arbitrarily large by the user or the system manager. The Student Edition version is limited to variables of size 32 by 32. 1.3.2.2. How does MATLAB index its matrices ? MATLAB began as a FORTRAN program and we have kept the convention of beginning our indices at one instead of at zero. You also cannot have negative indices to vectors of matrices. 1.3.2.3. Can MATLAB handle multidimensional arrays ? Many MATLAB users commonly ask the question, "Can I use multidimensional arrays in MATLAB?" The anwser is both yes and no. No, in that multidimensional arrays are not built into MATLAB. MATLAB's internal data stucture is limited to a two-dimensional matrix. But you can create your own functions in the MATLAB language to handle multidimensional arrays. The following is an example that maps a three-dimensional matrix to a single vector. The indices are passed to a function as if it were a three-dimensional matrix. Then the indices are translated to a single vector with corresponding offsets. The exact implementation will be specific to what you want to accomplish.
%INDEX3 POSITION = INDEX3(d,i,j,k) index a 3-D array % d is a vector that specifies the dimensions on the array function position = index3(d,i,j,k) position = (i+(j-1)*d(2)+(k-1)*d(2)*d(3));

The following is an example of how you might use this function.


D = [9 9 9]; A = 1:(9*9*9); A(index(D,5,4,4)) = 77; B = A(index(D,5,4,4)); % % % % D give the dimensions as 9x9x9 A is where your 3D data is Write to it Read from it % stored

You can create N-dimensional arrays with different limits on each dimension. The main difference is that you would change how the offset is indexed through your matrix. Each additional dimension would require a corresponding offset. You can add error checking for the indices to make sure you do not go out of bounds.

1.3.2.4. How can I initialize a low rank matrix easily ? 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))]

1.3.3. Functions
1.3.3.1. Why, when I edit a function file in MATLAB, is the change not seen by MATLAB until everything is cleared or MATLAB is restarted? When you write an M-file in MATLAB, you can either write a script or a function. The difference is that a script is read from the disk and parsed line by line each time it is called. A function is loaded into RAM for execution. Because it is loaded into RAM, when you edit a function, that change is not loaded into RAM until a call to the new function is made. To get MATLAB to recognize your edited function, type
clear functions

to clear all functions, or


clear <function name>

to clear just your function out of RAM. 1.3.3.2. How can I get the parser to accept a dummy reference without an error? MATLAB parses code to look for syntax errors. When the parser encounters a name with two or less arguments, it lets them pass since they might be a variable with indices. If it encounters a name with three or more arguments, MATLAB knows it cannot be a variable, so the error message is returned. If you don't want the parser to snag the function, specify one with twp or less arguments. 1.3.3.3. Is there a GNU emacs editing mode for MATLAB? A GNU emacs 'matlab-mode' is available via anonymous ftp from csi.jpl.nasa.gov as pub/matlab/util/matlab-mode.el or, ftp.mathworks.com as
/pub/contrib/tools/matlab-mode.el.

1.3.3.4. Does MATLAB have a debugger? Yes, MATLAB does have a debugger. To find out more, type

help debug

at the MATLAB prompt.

1.3.4. eval Command


1.3.4.1. How does the eval command work? The eval command evaluates any expression given as its input. This is described in detail in a technical note which can be found on the ftp server in pub/tech-support/technotes/mat3.txt.

1.3.4.2. How can I use a filename that is a variable as an input argument to the load, save, and print functions?
name = 'xyz.mat'; eval(['save ', name]); eval(['load ', name]); name = 'myfigure.ps'; eval(['print ',name]);

1.3.5. MATLAB Functions


1.3.5.1. Why was fsolve removed from MATLAB Version 4? The algorithms used by fsolve were not numerically well behaved. MathWorks did not feel that these algorithms met the standards required for approved software. We recommend the version of fsolve in the Optimization Toolbox . If your site doesn't have the Optimization Toolbox, you can get the old version of fsolvefrom
ftp.mathworks.com in /pub/contrib/optim/fsolve35.

1.3.5.2. What is griddata? How do I use it to contour irregularly spaced data?


griddatais a function that interpolates your data to generate evenly spaced data for plotting.

Example: x,y,z => irregularly spaced data


xmin=min(x); ymin=min(y); xmax=max(x); ymax=max(y); xi=xmin:0.02*(xmax-xmin):xmax; yi=ymin:0.02*(ymax-ymin):ymax; zi=griddata(x,y,z,xi',yi); contour(xi,yi,zi)

1.3.5.3. What is the sign convention used in MATLAB's fft routines?

The fft in MATLAB is defined as sum(x(i)*exp(-j*i*k/N)) and not sum(x(i)*exp(j*i*k/N)). The first version is traditionally used by engineers, the second version by mathematicians. 1.3.5.4. How do I fit a curve in MATLAB? There are many ways to fit a curve in MATLAB. The most common is to use polyfit to fit your data to a polynomial. Here is an example of how to use polyfit to fit data:
x = 1:10; y = exp(x); % create exponential data to be fitted c = polyfit(x,y,9); % generate coefficients for a fitted of degree 9 yfit = polyval(c,x); % evaluate the polynomial at x plot(x,y,'yo',x,yfit,'r-') % plot the results

% polynomial

There is a technical note on fitting a function to data using leastsq which can be found on the ftp server under pub/tech-support/tech-notes/math4.txt.

1.3.6.File I/O
1.3.6.1.How do I use fread, fwrite, and fprintf?
fread , fwrite , and fprintf are all similar to their C counterparts and are used to read and

write data to a file. Each of these requires the use of a file identifier. These functions allow you to specify the format in which you would like your data read or written. To find out more, take a look at the online help available for these functions. Also, there is a technical note describing how to load and save data in MATLAB which can be found on the ftp server under pub/tech-support/tech-notes/io1.txt. 1.3.6.2.How can I store the result of ls *.dat in a variable?
[tmp,list] = unix('ls *.dat');

1.3.7. Differential Equations


1.3.7.1. Can MATLAB solve Ordinary Differential Equations (ODE)? MATLAB has four basic functions to solve ODE's, quad , quad8 , ode23, and ode45 .
quad uses an adaptive recursive Simpson's rule, quad8 uses an adaptive recursive Newton Cotes 8 panel rule, and ode23 uses the Runge-Kutta method. In addition to ode23 , there is an ode45 function, which uses a 4th and 5th order Runge-Kutta as opposed to ode23 's 2nd and

3rd order. 1.3.7.2. How do I pass in extra parameters to ode and quad?

ode23 and ode45 are called as follows: = ode45('yprime', T0, Tfinal, Y0)

where the inputs to the function are: F - String containing name of user-supplied problem description. Call: yprime = fun(t,y) where F = 'fun' . t - Time (scalar). y - Solution column-vector. yprime - Returned derivative column-vector; yprime(i) = dy(i)/dt. t0 - Initial value of t. tfinal- Final value of t. y0 - Initial value column-vector. tol - The desired accuracy. (Default: tol = 1.e-6 ). trace - If nonzero, each step is printed. (Default: trace = 0 ). The call to quad and quad8 is as follows:
Q = quad8(F,A,B,TOL,TRACE)

However, if you want to pass extra parameters to the function, do as follows:


Q = quad8('F',A,B,TOL,TRACE,P1,P2,...)

This allows coefficients P1, P2, ... to be passed directly to function F:


function g=f(a,b) G = F(X,P1,P2,...).

To use default values for tol or trace , you can pass in the empty matrix. For more information, take a look at the technical note on this topic. It can be found on the ftp site in pub/tech-support/tech-notes/math1.txt. 1.3.7.3.How do I do double integration in MATLAB?

A technical note has been written on how to do double integration in MATLAB. It can be found on the ftp site in pub/tech-support/tech-notes/math2.txt.

1.3.8.Memory
1.3.8.1.What can I do when MATLAB tells me I'm out of memory? If the OUT OF MEMORY error message is encountered, there is no more room in memory for new variables. You must free up some space before you can proceed. One way to free up space is to delete some variables (see clear ). Another is to issue the command pack (see pack ). pack compresses the data in memory, and open up larger contiguous blocks. Here are some additional system specific tips: MS-Windows: Increase the swap space by opening the Control Panel, double-clicking on the 386 Enhanced icon, and pressing the Virtual Memory button. Macintosh: Under Multi-Finder, change the application memory size by using Get Info on the program icon. Under Single-Finder, install more memory. VAX/VMS: Ask your system manager to increase your working set. UNIX: Ask your system manager to increase your swap space.

1.3.9.Student Edition
1.3.9.1.Why does my Student Edition hang my machine after the MATLAB banner is displayed? This happens from time to time, depending on your machine, because the binary codes for MATLAB are different from machine to machine. There is only one version of Student Edition for PC's. Here are two fixes for the problem: OPTION 1: Edit the matlab.bat file, add the following line above the pcmatlab line, set
N087=1 , so it will look like this: set NO87=1 (there are no spaces on either side of the =, and that is a letter O not the number 0.) pcmatlab .....

OPTION 2: Go to the MATLAB bin directory (cd matlab/bin) Copy PCMATLAB.EXE to PACMATLAB.ORG.

Rename PCMATLAB.EXE to PCMATLAB.DAT (using the DOS ren command) At the DOS prompt, type debug pcmatlab.dat and press enter. You will be at the left margin with a minus sign. At the minus, type rcs and it will return CS xyyy where x and y are numbers. You will then be at the colon prompt. At the colon prompt, hit return and you'll get back the minus prompt. At the minus prompt, enter e zyyy:11 where z=x+3, then press return. You should get back zyyy:0011 25 . Immediately following zyyy:0011 25 . type D followed by a space. This should return 3C. on the same line. Immediately following 3C. type 3F followed by a space. This should return FF. on the same line. Immediately following FF. , type 0 (zero) and press return. You will be back at the minus prompt. Enter w and press return. The text Writing 51F92 bytes will be displayed and you will be back at the minus prompt. Enter q and press return. You will be back at the DOS prompt. Rename PCMATLAB.DAT to PCMATLAB.EXE (using the DOS ren command). 1.3.9.2.How do I print using the Student Edition? Directions on how to print using the Student Edition of MATLAB can be found in the Student Edition manual on pages 27-28.

2. Graphics
2.1. Using get and set
2.1.1. What is a handle?
A handle is a number assigned by MATLAB to a graphics object. For example, you can have a handle to each object in a plot that contains many objects such as lines, patches, and surfaces.

Once you know the handle to an object, you can alter its properties. To find out what properties are associated with each object, see axis , figure , line , patch , surf , root , and image . If you wanted to get the handle to a line when you plot it, you would do the following:
handle=plot(x,y)

2.1.2. How do I use get and set?


You can either get or set a property of an object in the following manner:
get(handle,'PropertyName') set(handle,'PropertyName','PropertyValue')

Two common handles are gca and gcf which stand for 'get current axes' and 'get current figure', respectively. If you use gca or gcf as the handle in your get or set statement, you will be able to change the properties of the current figure or current axes without previously defining their handles. For more information, look at the MATLAB technical note written on this topic. It can be found on the ftp site in pub/tech-support/tech-notes/gr12.txt.

2.1.3.What properties can I control?


To find out about an object's properties, type the following:
set(handle)

This returns a list of all the properties associated with that object as well as each property's optional settings. The settings in { } are the default settings.

2.1.4.How do I change the default settings for an object's properties?


To set the default setting for an object, you first need to know the ancestor of the object whose property you wish to set. To find the parent of an object, type the following:
h=get(object's_handle,'Parent')

To set the default, type the following:


set(h,'DefaultObjectPropertyName','PropertyValue')

Don't put any spaces in the DefaultObjectPropertyName expression. A good example of how to do this is the following:
set(gca,'DefaultLineLineWidth',10)

Any line you plot after this statement will have a line width of 10.

2.1.5.How do I change the default settings back to their original settings?


Set the default settings just as explained above, but use factory for the property value. For example, if you changed the default line width to 10 as above and then you wanted to set it back to the original setting, you would type:
set(gca,'DefaultLineLineWidth','factory')

2.2.Properties of the Figure and the Axes


2.2.1. Fonts
How do I change the font of labels? When you change the default font name and font size, the factory settings will still be used when drawing the title and lables on the screen. Following is a modified xlabel, ylabel, zlabel, and title to recognize changes to the default FontName and FontSize; however, it would be just as easy to have it recognize changes to all the default text font properties. Below are the revised programs:
<------XLABEL.M ------->

function xlabel(string) % XLABEL X-axis labels for 2-D and 3-D plots. % XLABEL('text') adds text below the X-axis on the current % axis. % % See also YLABEL, ZLABEL, TITLE, TEXT.

Copyright (c) 1984-92 by The MathWorks, Inc.

h = get(gca,'xlabel'); ht = get(text,'fontname'); hs = get(text,'fontsize'); if isempty(h)

h = text('HorizontalAlignment','center'); set(gca,'xlabel',h); end set(h,'string',string,'fontname',ht,'fontsize',hs);

<-------

YLABEL.M ------->

function ylabel(string) % YLABEL Y-axis labels for 2-D and 3-D plots. % YLABEL('text') adds text beside the Y-axis on the current % axis. % % See also XLABEL, ZLABEL, TITLE, TEXT.

Copyright (c) 1984-92 by The MathWorks, Inc.

h = get(gca,'ylabel'); ht = get(text,'fontname'); hs = get(text,'fontsize'); if isempty(h) h = text; set(gca,'ylabel',h); end set(h,'string',string,'fontname',ht,'fontsize',hs);

<-------

ZLABEL.M ------->

function zlabel(string) % ZLABEL Z-axis labels for 3-D plots.

% ZLABEL('text') adds text above the Z-axis on the current % axis. % % See also XLABEL, YLABEL, TITLE, TEXT.

Copyright (c) 1984-92 by The MathWorks, Inc.

h = get(gca,'zlabel'); ht = get(text,'fontname'); hs = get(text,'fontsize'); if isempty(h) h = text; set(gca,'zlabel',h); end set(h,'string',string,'fontname',ht,'fontsize',hs);

<-------

TITLE.M ------->

function title(string) % TITLE Titles for 2-D and 3-D plots.

% TITLE('text') adds text at the top of the current axis. % % See also XLABEL, YLABEL, ZLABEL, TEXT.

Copyright (c) 1984-92 by The MathWorks, Inc.

h = get(gca,'title'); ht = get(text,'fontname');

hs = get(text,'fontsize'); if isempty(h) h = text('horiz','center'); set(gca,'title',h); end set(h,'string',string,'fontname',ht,'fontsize',hs);

For more information, see the MATLAB technical note written on this topic. It is located on the ftp site in pub/tech-support/tech-notes/gr2.txt. 2.2.1.1. How do I change the font of text objects? To change the font name or font size of a text object, do the following
set(h,'FontName','font')

where his the handle to the text object, and font is the name of the font you wish to use. For more information, see the MATLAB technical note written on this topic. It is located on the ftp site in pub/tech-support/tech-notes/gr6.txt. 2.2.1.2.How do I change the font of tick labels? Although undocumented, all the standard text object font properties such as FontName, FontBold, and FontItalic are also properties of axes. For example, typing:
set(gca,'FontStyle','courier')

will change the font of x and y tick labels before they are created. To change the font of existing labels, do the following:
h=get(gca,'Xlabel'); set(h,'FontName',font);

For more information, see the MATLAB technical note written on this topic. It is located on the ftp site in pub/tech-support/tech-notes/gr10.txt. 2.2.1.3. How do I get Greek letters in my text objects? You can obtain Greek characters from the symbol font. To implement:
h=text(x,y,'string') set(h,'FontName','courier');

or
set(gca,'FontName','symbol'); text(x,y,setstr(num));

where x and yare the coordinates on the graph where you want to place the Greek symbols, and num is the value from the list of 0-255 characters from the symbol font. To display a table of the symbol font, you can use the following M-file called chart.m.

function chart( fontname ) % CHART Show ANSI-chart like display of characters MATLAB %can produce. % % % % % % CHART( 'fontname' ) will put up a figure window with all 255 characters of the named font in a 16x16 grid. Close figure when done, it creates 256 text objects. You may want that memory back!

% % % % %

Chuck Packard, The Mathworks, Inc., 25 Jan 93 This is an unsupported, purely for example, Mfile.

% TO USE THIS CHART: % USE SETSTR( VALUE), WHERE VALUE=( (16*XCOORD)+YCOORD) % % % make a new figure and axis

% (I'm assuming you want to keep the current graph in the % % figure; axis([-1 16 -1 16]) ax = gca; % %set font to be used % set(ax, 'DefaultTextFontName', fontname ) % %some other Handle Graphics settings, written out in %full. %See manual for more info. % set(ax, 'YDir', 'Reverse', 'Box', 'on') set(ax, 'YTick', 0:15, 'XTick', 0:15) set(ax, 'DefaultTextHorizontalAlignment', 'Center') set(ax, 'DefaultTextVerticalAlignment', 'Bottom') % %not vectorized like all 'good' MATLAB M-files, but %easier to understand! % x = reshape( 0:255, 16, 16 ); for h=1:16 for v=1:16 gcf.)

text(h-1,v-1,setstr(x(v,h))); end end

2.2.1.4. Can I have multiple fonts in one text object? No, you cannot mix fonts, font styles, or font sizes within a text object.

2.2.2. Lines
2.2.2.1. How do I change the line width? To change the line width, do the following:
set(h,'LineWidth',size)

where h is the handle to a line and size is the width you want. The default line width is 0.5. 2.2.2.2. How do I change the line style order on printouts ? The following is an M-file that allows you to cycle through the line styles in the order you want when you print:

function prtlines(a1,a2,a3,a4,a5) % PRTLINES is a front-end to PRINT which converts % solid lines to various line styles for graphical % output. The change is transparent to the user.

% Non-solid lines are not affected. % % PRTLINES is used in the same manner as PRINT. % % The default line styles are: % %'. '

%'o ' %'x ' %'+ ' %'- ' %'* ' %': ' %'-.' %'--' % % The line style can be changed by editing the file % and changing the 'styles' array. % % SEE ALSO: PRINT, Properties of LINE % Written by John L. Galenski III % All Rights Reserved % LDM101493jlg 10/14/93

%% PRTLINES is an M-file developed by me for my own %% personal use, and therefore, it is not supported %% by The MathWorks, Inc., or myself. Please direct

%% any questions or comments to johng@mathworks.com. % Create the array of line styles. styles = [ '. ' 'o ' 'x '

'+ ' '- ' '* ' ': ' '-.' '--' ]; % Get the Children of the Figure. a = get(gcf,'children'); % Check the Children of 'a'. If they are

% solid lines, then change their LineStyle % property. for j = 1:length(a) l = sort(get(a(j),'children')); X = 0; Add = 0; for i = 1:length(l) if strcmp( 'line', get(l(i), 'type' )) if strcmp(get(l(i),'linestyle'),'-') X = X + 1; LINE = [LINE;l(i)]; SI = rem(X,length(styles));

if SI == 0 Add = 1; end set(l(i),'linestyle', styles(SI+Add,:));

end end end end % Construct the PRTCMD. PRTCMD = 'print'; for x = 1:nargin PRTCMD = [PRTCMD,' ',eval(['a',int2str(x)])]; end

% Discard the changes so that the Figure is not % updated. drawnow discard eval(PRTCMD)

% RESET THE LINESTYLES set(LINE,'linestyle','-')

% Discard the changes so that the Figure is not % updated. drawnow discard

2.2.2.3. How do I cycle through the line color order? You can set the default color order for the axes by doing the following:
set(gca,'ColorOrder',A)

where A is an RGB vector of any length.

2.2.3. Positions
2.2.3.1. How do I change the size and position of my figure window? There is a property of the figure window called Position where the x-position, y-position, width, and height are stored. To change this, do the following:
pos=[x_position, y_position, width, height]; set(gcf,'Position',pos)

2.2.3.2. How do I define an invisible axis? There is a property of the axis called Visible. You can set Visible to off as follows:
set(gca,'Visible','off')

This is very useful if you want to place text in the figure window with respect to the borders of the figure, rather than with respect to the axes. 2.2.3.3. Which units should I use? There are five different types of units you can use: inches, centimeters, normalized, points, and pixels. To make sure what you get out of your printer looks like what you have on your screen, we recommend using normalized units.

2.3. Background Color


2.3.1. How do I invert the background on my printout?
set(gcf,'InvertHardCopy','on')

2.3.2. How do I change my background for plots?


To change the background color of your plot from black to white, type cinvert at the MATLAB prompt. To make the default setting white, place the following line in your startup.m file
whitebg

To change the color of your figure window to something other than black or white, type the following:
set(gcf,'Color','red')

2.4. Using MATLAB Graphs with Other Packages


2.4.1. Can graphics be saved as files to be imported back into MATLAB for viewing and alteration?
Yes, in MATLAB version 4.2. A new print command device driver option allows you to save and reload a figure. The command
print -dmfile <filename>

creates two files, filename.m and filename.mat. The M-file contains the necessary object creation and set commands to reproduce the figure. The generated MAT-file also contains the figure data. Handle values are not maintained.

2.4.2.Can I edit MATLAB graphs in other applications?


In MATLAB version 4.2, graphs are produced in such a way that, if your application allows you to view the imported figure, you can edit it.

2.4.3. How do I copy and paste MATLAB graphs to the clipboard?


To copy and paste MATLAB figures to the clipboard, select Edit from the menu at the top of the Figure window. Then select Copy. Your figure now exists in the clipboard. To paste, simply choose Paste from the Edit menu in your application.

2.5. Graphical User Interface (GUI)


2.5.1. How do I make a dialog box?
MATLAB version 4.2 has some functions that will help you do this. See help on dialog for more information.

2.5.2. How do CallBacks work? What is the best way to write a CallBack?
A CallBack is the specified action that MATLAB performs when the user selects the menu item to which the CallBack has been assigned. When the button or menu item is selected, the expression contained within the CallBack string is executed. For example:
h=uicontrol('Style','PushButton','String','title',... 'CallBack','disp(''hello'')')'

When you push on the button, hello will be displayed in the MATLAB workspace. The most efficient way to write a CallBack is to make the CallBack a function. That way, the function is stored in RAM and will execute more quickly if you are going to be using the button often.

2.5.3. Where do CallBacks get executed?


CallBacks get executed in MATLAB's main workspace.

2.6.Miscellaneous
2.6.1. Why does waterfall return a blank screen?
There is a bug in the waterfall routine which prevents the edgecolor from being accurately represented. To work around this, issue the following two commands:
h=waterfall(peaks); set(h,'edgecolor','w')

This will make the edgecolor for the whole waterfall a constant color and allow printing as well as display.

2.6.2. How do you get perspective with 3-D plots?


To change the ratio of the axis in a 3-D plot, you will need to change the xform property of the current axis. The property transforms the 3-D data to be plotted on the 2-D screen. The following M-file will do the trick.
function aspect3(x,y,z) v = get(gca,'xform'); d = diag([x y z 1]); set(gca,'xform',v*d);

2.6.3. Why does MATLAB sometimes draw patches out of order?


MATLAB determines the order in which patches are drawn by using the Painter's Algorithm. It determines which patch to draw first by determining which vertices of each patch are closest to you, the viewer. If a few patches have overlapping vertices, then MATLAB must choose which patch to draw first. Sometimes it chooses incorrectly.

2.6.4. How do I use multiple colormaps?


Here is an example:
% % Place a gray PCOLOR of PEAKS and hsv SURF of PEAKS in the same plot.

clf hold off

% Set the colormap colormap([gray(30);hsv(30)])

% Generate the data = peaks(30);

% Create the Cdata for the PCOLOR and SURFACE plot. % The Cdata for each plot should be contiguous, and % not overlap. This will guarantee that they use

% different regions of the colormap. cd1 = z + abs(min(min(z))); cd2 = cd1 + max(max(cd1)) + 1;

% Place the PCOLOR P = pcolor(cd1); shading interp

% Change the location so that it will be visible when % the SURFACE is drawn set(P,'zdata', -30*ones(size(get(P,'zdata')))) hold on

% Place the SURFACE plot S = surf(1:30,1:30,z,cd2);

% Change the location so that it does not overlap the % PCOLOR %set(S,'zdata',15+get(S,'zdata')) % Change the Clim used by AXES set(gca,'clim',[min(min(cd1)), max(max(cd2))])

% Make sure that the VIEW and AXES limits are correct view(3) axis([1 30 1 30 -30 30])

% Rules that you need to follow when doing this. % %1) The Cdata values for each plot should

%not overlap. % %2) The range between the minimum and maximum

%values in Cdata should be the same for each %plot. % %3) % %4) Set Clim for AXES to range from the The Cdatas must be contiguous.

%smallest and largest values of the 2 Cdatas.

2.6.5. What is the difference between pcolor and image?


Each element in the image's CData is used to color a rectilinear patch. The data contains the row of the colormap used to color the patch.

pcolor

is a surface plot and its CData is scaled into the colormap. Each element of the CData corresponds to a vertex in the plot. Therefore, the number of rectangles in pcolor is always one row and column smaller than the actual data.

3. Printing
3.1. General
3.1.1. How do I print in MATLAB?
To print a figure window from the command line, type print. If you would like to use any of the options, type
print -<option>

For more information, type


help print

at the MATLAB prompt. If you are working on a Macintosh or a PC, you can also print from the File pulldown menu on the Figure window (for Macintoshes, make sure the Figure window is the selected window).

3.1.2. How do I print a SIMULINK block diagram?


To print a SIMULINK block diagram, type print -f<systemname> at the MATLAB command line. You can use the options found in help print when printing a SIMULINK diagram. If you are working on a Macintosh or a PC, you can print from the File pulldown menu, just as you would print a figure.

3.2.GhostScript
3.2.1.What is GhostScript? How do I use it?
GhostScript is a shareware product that converts PostScript to other file formats. You would use this if you wanted to print to a printer that does not accept PostScript. If you just use print without any device, it uses the default printer file format of your system. For a complete listing

of GhostScript devices supported by MATLAB, type help print at the MATLAB command line.

3.2.2.Where can I get documentation for GhostScript?


To obtain a copy of use.doc, you can download the file from the MathWorks FTP server in /pub/doc/ghostscrip. If you do not have access to FTP, please contact Technical Support. The makers of GhostScript can be contacted at the following: Phone: 617-876-3296 Email:
gnu@prep.ai.mit.edu

3.2.3.Why would I print with a GhostScript device?


Users print with GhostScript devices if they want to generate a file on one system and print on another. Sometimes, you get better quality printouts if you use a device that is specific to your printer, rather than using the default device (which is -dps ). Also, if you are printing to a nonPostScript printer, you should specify the type of printer driver you will be using so as not to invoke the default.

3.2.4.What do I do if my printer isn't listed among the GhostScript devices?


If your printer is not listed among the GhostScript devices, look to see if your printer is compatible with one of them. If there isn't a device that is compatible with your printer, just use the print command and MATLAB will choose your system's default printer.

3.2.5.How do you use GhostScript to display PostScript files to the screen from DOS?
There are three ways: Quickest way: Create a directory called C:\GS Copy all files in the directory $MATLAB\GHOSTSCR\BIN , $MATLAB\GHOSTSCR\PS_FILES, and $MATLAB\GHOSTSCR\FONTS to C:\GS (where $MATLAB represents the MATLAB root directory) Copy the PostScript file to C:\GS CD to C:\GS
Execute the command GS386 <postscriptfilename>

where <postscriptfilename> is the whole name, including the .ps extension. If for some reason this doesn't work, try

DOS4GW GS386 <postscriptfilename> .

Clean but somewhat cumbersome: CD to the $MATLAB\GHOSTSCR\BIN directory Execute the command
GS386 -I..\PS_FILES -I..\FONTS <postscriptfilename>

where here <postscriptfilename> represents the full path name to the postscript file. Clean and easy but more permanent: Add $MATLAB\GHOSTSCR\BIN to your DOS path. In the AUTOEXEC.BAT file, set an environment variable called GS_LIB as follows:
set GS_LIB = $MATLAB\GHOSTSCR\PS_FILES;$MATLAB\GHOSTSCR\FONTS

(where $MATLAB is replaced by the MATLAB root directory.) Now to use GhostScript you can type gs386 <postscriptfilename> from any directory.

3.3. Printing to a File


3.3.1. How do I print to a file?
To print to a file, type the following at the MATLAB prompt:
print -<device> <filename>

3.3.2. How do I know what option to use?


If you type
help print

at the MATLAB command line, you will see a list of options. There are two types of options, Windows printing options and miscellaneous options. The miscellaneous options allow you to create an .epsi file (which is an encapsulated PostScript file which can be previewed), append your graph to a file, specify the printer to use, and print a SIMULINK diagram.

3.3.3. How do I print out an HPGL format file?

In MATLAB version 4.2 there is a GhostScript device for HPGL. If you are using MATLAB 4.1.1, 4.1 or 4.0, this option does not exist. The only way to generate an HPGL format file is on the Windows version where you must specify an HPGL printer driver as your default printer. Then, under the File pulldown menu, select Print. In the lower left-hand corner of the Print box is an option to print to a file. Select this option and then select OK. You will then be prompted for an output filename.

3.4. SIMULINK Printing


3.4.1. How do I change fonts in SIMULINK?
SIMULINK models will always print with Times-Roman of point size 10. You cannot change this from inside MATLAB/SIMULINK. You can edit the PostScript file by hand. Be warned, however, the text will not be centered well. You can look near the top of the drawing commands to find the lines:
/Times-Roman findfont dpi2point mul 0 0 10 dpi2point mul neg 0 0]

The /Times-Roman is the font name you can change. The occurance of 10 on the second line is the point size.

3.4.2.What do I do if I am getting SIMULINK blocks and no text?


The workaround is to search the PostScript file for a sequence: 0 0 0 0 MR c np and comment out the line using a %. The diagram should then appear in the printout. If it is off center (which it probably will be), there is another place in the .ps file to edit the position on the page. To move the position of a SIMULINK block diagram on the paper, find the instance in the .ps file which has four numbers, then the words: bbox landscape csm . (search on bbox ) These numbers represent llx lly ulx ury, where ll is lower left, ur is upper right, etc. Remember, the figure is mapped to landscape, so it gets rotated 90 degrees It may be necessary to play with these numbers to get good figure placement. This bug has been fixed in MATLAB 4.2 / SIMULINK 1.3.

3.4.3. How do I print my SIMULINK diagram on more than one page?


It is not possible to spread your SIMULINK diagram out over more than one page. SIMULINK scales your diagram to fit on one page.

3.4.4. How do I print a SIMULINK model from within an M-file?


This only works for UNIX (because of the print switch, -s). It has been added to the PC for MATLAB 4.2.
function printsys(sys) open_system(sys);

blocks=get_param(sys,'blocks'); = size(blocks); for i=1:r if( get_param([sys,'/',blocks(i,:)],'blocks')~=[] ) open_system([sys,'/',blocks(i,:)]) %disp(blocks(i,:)) print('-s') end end close_system(sys)

3.5.Common Problems
3.5.1. Why does my printer hang when I try to print from the pulldown menu?
This appears to be a problem with the LaserJet IV driver initialization. One way we have found to work around the problem is to print a blank Figure window before printing anything else to the LaserJet. This will print a blank piece of paper, and also has the side effect of properly initializing the driver. After this, you should be able to print without any problems. Note that this blank Figure window only needs to be printed once per Windows session. If you quit and restart Windows for some reason, though, you will need to reprint the blank figure. This has been fixed in 4.2.

3.5.2. Why, after a long session of MATLAB under MS Windows where many figures printed, do I start to have a problem printing?
When printing several plots, there is a depletion of the system resources under Windows, and even after exiting MATLAB, the resources are not reallocated. This happens to the point where either you can not print anymore or the machine you are working on crashes. This is more of a problem with Windows than MATLAB. Windows will not reallocate system resources even after you have exited the application. You have to exit Windows and then restart Windows in order to get all of the system resources back. This can be reproduced both from MATLAB and from MS EXCEL . There is no clean solution to this problem other than printing to a file first and then sending the file to the printer. Microsoft anticipates that Windows 4.0 will do a better job in handling system resources.

3.5.3. Why don't my axis labels print correctly?


Sometimes, when you set the paper position in order to generate a small figure, the output title and axis labels are not printed correctly. You may only see the top or bottom half of the text in question depending on where it is in the figure.

So that axis labels and tick mark labels do not overwrite each other, they are always some absolute distance from the axis line. The one caveat is that axis position is relative to the size of the figure and, when rendering to paper, the PaperPosition. When you've got a really small figure or have set the PaperPosition, the axis is very close in absolute coordinates (i.e., it's only 1/2" away rather than 3/4" from the edge of the window or the clipping edge of PaperPosition). The same thing can be seen by making the window really small. A possible work around:
set(gca,'pos',[.2 .2 .7 .7],'units','norm')

Then adjust your output size to accommodate.

3.5.4. Why can't I print broken lines?


You are probably using the Windows driver or the actual printer driver that came with the printer. Levels 4, 3, 2, and 1 of PCL do not support broken line types. PCL level 5 supports broken line types. Most other software packages break the lines before presenting them to the printer--we do not. You need to use the GhostScript drivers or use PCL 5, which supports LaserJet 4's and up. PCL 5---Laser jet 4 PCL 4---Laser jet 4,3 PCL 3---Laser jet 4,3,2 PCL 2---Laser jet 4,3,2,1 In version 4.2 of MATLAB, you have the option of using the Windows/printer drivers to get broken lines but the lines will be thinner. This is a trade off because you get really good fonts from the windows drivers but thin lines and you get less than perfect fonts from the GhostScript drivers but thicker lines. See page 84 of the 4.2 Release Notes.

3.5.5.Why can't I print UI controls?


You can't print UI controls because they are Motif/ Window widgets, and Motif/Windows only draws into an X Window/Window, not hardcopy devices. UNIX Workaround: Use the command capture , which captures the current figure into a matrix, and then displays it in another figure window using the image command. The new image can then be printed normally (but the uicontrols in the image don't work, obviously). Since this method involves printing a bitmap image of the screen, the printout may not have as high a print resolution as the hardcopy results of the print command.

PC Workaround: There is no capture command for the PC version. One workaround is to use Windows handling of PRINTSCREEN. Select the figure that you want to print and press Alt-PrintScreen. A copy of the current window will be placed on the clipboard. This image can be pasted into another application for printing. One undesirable attribute of this workaround is that the Windows window titles and menus are included in the image. These sections of the image can be "cut" using Windows PaintBrush program.

3.5.6.Why, when I use interpolated shading or print surfaces, does my graph look "blocky" when the graph looked fine on the screen?
The reason for this is that when you use shading interp , each pixel can have a different RGB value, but when you try to print this, each surface face is broken into 4x4 blocks and assigned a specific color to each of the blocks. To work around this problem, simply increase the number of faces on your surface and don't use shading interp , use shading flat . To increase the number of surface faces, use griddata :
[xi,yi,zi] = griddata(x,y,z,0:.1:10,0:.1:100)

where x , y, and z are your original data, 0:.1:10 and 0:.1:100 are your new and increased ranges for x and y . Then use xi , yi , and zi in your surface command. For more information, see the MATLAB technical note written on this topic. It is located on the ftp site in pub/tech-support/tech-notes/gr1.txt.

3.5.7.What do I do if my PC beeps and hangs when I try to print?


This problem has been known to occur witth the LaserJet 4 and the DeskJet printer drivers. We have found that using the latest versions of these drivers will solve the problem. The latest LaserJet 4 driver is available on the ftp site in pub/tech-support/drivers/laser4_drv . The latest DeskJet driver is also available on the ftp site in pub/tech-support/drivers/desk_drv . In both cases, you should download the entire directory on to your PC and follow the instructions in the README file. If you find that this doesn't solve the problem, please contact Technical Support.

4.License Manager
4.1.Installing MATLAB

4.1.1.Are there step by step instructions for installation?


Yes, these instructions can be found in the README.install file. In addition, a complete guide to the license manager can be found in README.license file which is located in your $MATLAB/etc directory. However, it is important for you to read your Installation Guide first.

4.1.2.When should I run lmdebug?


You should run the script lmdebug if you are unable to start MATLAB. Once you have run the lmdebug script, take a look at what is in the Output of lmstat -a section. This should describe the problem that is keeping you from running MATLAB.

4.1.3.When do I have to run the license manager?


You need to run the license manager in all but the following two cases: You have demo passcodes ( DEMO is located at the end of your encryption codes in your license.dat file) You have a CPU locked Multi-User License (your hostid is located at the end of your encryption codes in your license.dat file and you have more than key). See page 9 of your Installation Guide if you are running on a VAX or page 1-14 if you are running on a UNIX system.

4.2.License Configurations
4.2.1.How do I set up the license manager so that it runs on a heterogeneous network?
A heterogeneous network means you're running a floating license on, say, both a SUN and a DEC using one license server. You can combine both installations of SUN and DEC MATLAB onto one machine, but we recommend against this since it involves a custom installation. This description assumes that you have a separate DEC area where you will install DEC MATLAB and a separate SUN area where you will install SUN MATLAB. Install MATLAB from the tape onto each machine, using the install option for STANDALONE/SERVER machines. For any client machines of the DEC and SUN, make sure the MATLAB client DEC machines have their matlab command access $MATLAB/bin/matlab on the DEC platform. Likewise, SUN MATLAB client machines should have their matlab command access $MATLAB/bin/matlab on the SUN platform. Decide which machine is the license server. In this example we will consider the DEC machine to be the license server.

The DEC license file should contain the DEC lmhostid, the DEC lm_matlab vendor daemon and passcodes based on the DEC lmhostid. In the SUN $MATLAB/etc directory, create a link for the license.dat file to point to the DEC $MATLAB/etc/license.dat . Start the license manager from the DEC license server machine. Keep in mind that for different platforms to work together, they must be using compatible versions of the license manager. For example, if you have V3.5j on the SUN, you cannot combine it with V4.1 for the DEC since they contain incompatible versions of the license manager. More specifically, the SUN MATLAB will call lmgrd on the DEC and place it in an incompatible state. It will not be able to run properly.

4.2.2.On a UNIX network, how do I run a back-up server configuration?


This configuration is only allowable for floating network licenses. Consider the following license file using a Sun-4 based license manager: ---------------------------------------------------------------------------- p>#License file for use
with FLEXlm version 2.4c. SERVER pooh 55419ab7 1705 SERVER piglet 554251b8 1705 SERVER rabbit 52006ac1 1705 DAEMON MLM /usr/local/matlab/etc/lm_matlab FEATURE MATLAB MLM 1 01-jun-2012 99 6B283ACADCE90BE190B7 "" FEATURE SIMULINK MLM 1 01-jun-2012 99 EB689A7AE885CDB2E0A3 ""

---------------------------------------------------------------------------To bring up the three license managers interactively, do the following after installation. Login to pooh. Become root. cd /usr/local/matlab/etc . Run lmstart . Login to piglet. Become root. cd /usr/local/matlab/etc . Run lmstart. Login to rabbit. Become root. cd /usr/local/matlab/etc . Run lmstart . To have the license manager daemons started at boot time, follow the directions in the Installation Guide to place the Bourne shell code fragment into the appropriate boot script.

The /etc/lmboot link must exist on each of the servers. To create this link on a given server, first login to the server and then, as root, run:
# $MATLAB/etc/lmboot -s

where $MATLAB is the location of the MATLAB root directory. Please note that at least two of the machines must always be running in order to create a network quorum. If only one of the three machines is running, no licenses will be available until a second server regains a running status. The order of the servers is also important. The first server will be the primary server and if this machine fails, the primary server will be designated as the next server listed in the license file. You must submit all three servers' hostids in order for the passcodes to be be properly generated for this configuration.

4.2.3.How do I combine license.dat files if I am running another vendor that uses FlexLM?
In V2.21 (or older) of the license manager, this was not possible; you could not combine two counted licenses of the same FEATURE names in the license.dat file. V2.4c of the license manager offered the option to enable multiple FEATURE lines of the same name into one license.dat file. For this to work, it is necessary to place all the floating license FEATURE lines before all the node-locked FEATURE lines. To start other vendors' daemons you must create: A merged license.dat file with all the DAEMON and FEATURE lines associated with each vendor daemon. A modified $MATLAB/etc/lmboot script. After installation the lmboot script needs to be modifed to know about each additional vendor daemon in the license file. This is so that the temporary license file in /usr/tmp can be created correctly. This example demonstrates what needs to be done. Consider having both MATLAB and another vendor's daemons started by MATLAB's license manager daemon with the following license file: ---------------------------------------------------------------------------- p>#License file for use
with FLEXlm version 2.4c. SERVER radical 52201985 1700

# DAEMON MLM /usr/local/matlab/etc/lm_matlab FEATURE MATLAB MLM 1 01-aug-1995 3 6B486F9FDB9F99083820 "" FEATURE SIMULINK MLM 1 01-aug-1995 3 8B38FF3F695F028F93A8 "" FEATURE Control_Toolbox MLM 1 01-aug-1995 3 2B18BFEF0BB457E414B5 "" # DAEMON XXX /usr/local/XXX/license/bin/XXX FEATURE XXX XXX 3.100 01-aug-1995 1CBB4ACD78C0C77ABE123 ""

---------------------------------------------------------------------------You need to remember the DAEMON names when making the code changes. In this case the only additional DAEMON name is XXX . Below is a Bourne shell code section from lmboot . The part between the "======" lines must be modifed. For each DAEMON you must add three lines such as:
NAME) ln -s $daemonPath /usr/tmp/$marker.vd$ndaemon ;;

The only thing that should change is NAME . It must be the name of the DAEMON. For PVI it would be
PVI) ln -s $daemonPath /usr/tmp/$marker.vd$ndaemon ;;

Note that these lines for PVI are already shipped in the script, except the lines are commented out. To activate them simply remove the # or comment character from the beginning of the lines as indicated below. If there are additional daemons, then three more lines for each daemon must be added. In order for the process command names given by the ps command to look the same across platforms, the symbolic link created in the three-line script section above should refer to a binary daemon program, not a script. This means the daemon path given by the third field of the DAEMON

line (referred to as $daemonPath in the script) should be a path to a binary program. Note that for MATLAB this is not true. So a special value for the daemon path which refers directly to the binary is used.
# #Create temporary license.dat file by copying and modifying the original file # rm -f /usr/tmp/$marker.dat > /dev/null 2>&1 rm -f /usr/tmp/$marker.vd* > /dev/null 2>&1 ndaemon=0; (while read line do field1=`echo $line | awk '{print $1}'` if [ "$field1" = "DAEMON" ]; then daemonName=`echo $line | awk '{print $2}'` # field 2 daemonPath=`echo $line | awk '{print $3}'` # field 3 ndaemon=`expr $ndaemon + 1` case "$daemonName" in # Always assume $MATLAB/etc/$Arch/lm_matlab # Must use the binary - NO SCRIPTS ln -s $MATLAB/etc/$Arch/lm_matlab /usr/tmp/$marker.vd$ndaemon ;; #============================================================ # ADD OTHER DAEMONS HERE. Example, PV-WAVE. Uncomment lines. # Add other case statments for additional daemons. # PVI) # Use the daemonPath - arch binary already

ln -s $daemonPath /usr/tmp/$marker.vd$ndaemon ;; #============================================================ *) # daemons you forgot ndaemon=`expr $ndaemon - 1` #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ echo '' echo 'Sorry! Skipped following DAEMON line. Fix $MATLAB/etc/lmboot script.' echo '' echo "$line" echo '' #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ continue ;; esac echo "$line" | sed "s%$daemonPath%/usr/tmp/$marker.vd$ndaemon%" >> /usr/tmp/$marker.dat else echo "$line" >> /usr/tmp/$marker.dat fi done) < $licensefile

4.2.4.How do I run two versions of MATLAB on a VAX?


The MATLAB environment, which needs to be modified to run different versions of MATLAB, consists of two logical names.
MATLAB TOOLBOX

When installed as described by the installation document, the logical names are defined on a system-wide basis at boot time through the execution of MATLAB:[ETC]MATLAB_SYSTARTUP.COM from SYS$MANAGER:SYSTARTUP_V5.COM . (See installation guide steps 8) Symbols used to invoke MATLAB and its utilities, such as CMEX, are defined on a per-process basis through the execution of MATLAB:[ETC]MATLAB_SYLOGIN.COM from SYS$MANAGER:SYLOGIN.COM at login time. (See Installation Guide step 9) If you want to maintain a MATLAB v3.5 environment and have the ability to run MATLAB v4.x, omit steps 8 and 9 of the installation procedure. Instead, following completion of the installation procedure, perform the following steps using the editor of your choice: Copy the lines from MATLAB_SYSTARTUP.COM which define the logical names MATLAB and TOOLBOX to MATLAB_SYLOGIN.COM . The lines in MATLAB_SYSTARTUP.COM look like this:
$ DEFINE/SYSTEM/EXEC/TRANS=CONCEALED MATLAB DISK$USER:[MATLAB.] $ DEFINE/SYSTEM/EXEC/TRANS=CONCEALED TOOLBOX DISK$USER:[MATLAB.TOOLBOX.]

Place these lines so they are the first commands to executed by the file. From these lines remove the "/SYSTEM" qualifier, so they look like this:
$ DEFINE/EXEC/TRANS=CONCEALED MATLAB DISK$USER:[MATLAB.] $ DEFINE/EXEC/TRANS=CONCEALED TOOLBOX DISK$USER:[MATLAB.TOOLBOX.]

Save MATLAB_SYLOGIN.COM and exit. (Do not save MATLAB_SYSTARTUP.COM .) Now to setup the environment to run V4.x simply type:
@DISK$USER:[MATLAB.ETC]MATLAB_SYLOGIN

4.3.Common Error Messages:


4.3.1.Cannot Connect to License Server
Possible Solutions: Check whether the license daemons are running. Do a ps as indicated in the troubleshooting section of the Installation Guide. If the license daemons are not running, you should execute lstmart . With a CPU-locked MultiUser license, however, the license daemons do not need to be run, so you should try starting MATLAB and let us know if you're getting any errors.

Check that the DAEMON line in the license.dat file is pointing to the correct location for lm_matlab . Make sure the host name on the SERVER line in the license.dat file is correct. Make sure the the UNIX ping <hostname> command returns <hostname> is alive where hostname is the name of the MATLAB server machine. If the ping command returns the error, <hostname> is not responding , then there is a problem with your network configuration such that connection to that machine will fail. Connection to the license daemons will, therefore, also fail. Make sure that the network software TCPIP is running on your machine. Even for stand-alone machines, the license manager requires TCPIP.

4.3.2.XXX Feature is not Currently Licensed


Possible Solution: It may be a typographical error in the feature line indicated by the error. For example, this error will occur if Signal_Toolbox is entered as signal_toolbox . Check the error message for typographical errors and case sensitivity in the name of the feature. Make sure the FEATURE line matches the passcodes as generated by The MathWorks, Inc.

4.3.3.Environment Variable of lm_license_file Not Defined


Possible Solution: The user is running the matlab executable in, say, $MATLAB/bin/sun4, rather than the matlab script in $MATLAB/bin. Note that sun4 can be replaced with any architecture we support, like RS/6000. You may have the wrong matlab on the UNIX path or you may need to rerun install_matlab to set up the correct paths.

4.3.4.No TCP License Server Exists


Possible Solutions: You do not have TCPIP software on your machine. To check, execute the UNIX ping command. e.g., ping <hostname> where hostname is the name of the machine from which you're trying to run MATLAB. If ping is successful, see (2) below. You probably do not have 1700 at the end of the SERVER line in the license.dat file.

4.3.5.Invalid Returned Data From License Server

Possible Solution: You probably installed the latest version of MATLAB (which uses FLEX 2.4c) without shutting the old (v2.21) license daemons. This error indicates that you are running a version of FLEXlm older than 2.4c. You need to execute lmstart in V4.1 of MATLAB which executes the lmgrd and lm_matlab license daemons which ship with MATLAB 4.1.

4.3.6.License Server Does Not Support This Feature


Possible Solutions: You probably received new codes and did not restart the license manager. You can also try doing an lmreread . Make sure you do not have a typographical error in the FEATURE line spelling.

4.3.7.Unable to Read License File


Possible Solution: The problem occurs with the logical LM_LICENSE_FILE set to NODE:FILE_SPEC. MATLAB compiled with the VAX C compiler does not support accessing a license file through DECNET. This is because access to the license file is checked with a C standard runtime library routine called access. The VAX C runtime library access routine explicitly does not support access to a file through DECNET. LM_LICENSE_FILE must point to a local license.dat file. This license.dat can be a VAX CLUSTER file, which is the equivalent of NFS mounting under UNIX.

5.SIMULINK/MEX-Files/Engine
5.1.SIMULINK
5.1.1.Printing SIMULINK models
5.1.1.1.How do I print my SIMULINK model? To print a SIMULINK block diagram, type print -f<systemname> at the MATLAB command line. You can use the options found in help print when printing a SIMULINK diagram.

If you are working on a Macintosh or a PC, you can print from the File menu, just as you would print a figure. 5.1.1.2.Why doesn't the text on my SIMULINK diagram print out? This was a bug in SIMULINK version 1.2 and MATLAB versions 4.0 thru 4.1.1. It has been fixed in SIMULINK version 1.3 and MATLAB version 4.2.

5.1.2.MATLAB Function block


5.1.2.1.Why can't I call any MATLAB function from the MATLAB Function block? The MATLAB Function block can take any number of inputs, but it must return a vector as an output. 5.1.2.2.What is the difference between the MATLAB Function block and the function block? The MATLAB Function block can perform any function in MATLAB, whether it is a function you have written or one that comes with MATLAB. The Function block can use only a limited number of functions (the list of these functions can be found by clicking on Help in the function block). This block uses C routines to perform the calculations and is therefore very fast.

5.1.3.General Questions
5.1.3.1.How do I mask SIMULINK blocks? There is a technical note on masking SIMULINK blocks, which can be found in pub/techsupport/tech-notes/sim3.txt.

5.1.3.2.Why doesn't linmod return the correct results? There is a technical note which explains the uses and limitations of linmod which can be found in pub/tech-support/tech-notes/sim2.txt. 5.1.3.3.Can SIMULINK handle complex signals? No. The current releases through 1.3 are not designed to handle complex data. The real and imaginary parts must be separated and handled independently. 5.1.3.4.How do I use the set_param and get_param functions? There is a technical note which explains how to use these two functions which can be found on the ftp server in pub/tech-support/tech-notes/sim6.txt.

5.1.4.S-functions
5.1.4.1.What is the flag ordering for S-functions? SIMULINK makes calls with flags in the following order: 4, 3, 2, 1. It might not call all of these flags, but flag calls are always made in this order, whether or not some flags have been skipped. 5.1.4.2.How do I display values numerically, rather than graphically (with the scope)? The following is an S-function example, which was written by one of the Technical Support Engineers:
function[sys,x0]=show(t,x,u,flag) if abs(flag)==0, hs1=figure('units','normal','pos',[.8 .8 .1 .2]); hs2=uicontrol(hs1,'style',... 'edit','units','normal','pos',[0 0 1 1], ...'min',0,'max',100); set(hs2,'string','DIG_SCOPE'); sys=[0 1 0 1 0 0]; x0= hs2; elseif abs(flag)==2, tempstr=get( x(1) , 'string' ); newstr=str2mat( num2str(u),tempstr ); % Keep the last 50 values [m n]=size(newstr); if m>50, newstr=newstr(1:50,:); end set( x(1) , 'string', newstr); sys= x(1); else sys=[]; end

5.1.4.3. Are there any examples of S-functions in C? FORTRAN? Aside from the examples, which can be found in the directory /simulink/blocks , our engineers are starting to build a library of examples. To find out more about these, contact support@mathworks.com .

5.2. MEX-Files and Engine


5.2.1. Compilers we support

There is a technical note, which contains a list of compilers along with many addresses and phone numbers for compiler companies. This technical note can be found in pub/techsupport/tech-notes/mxeng1.txt.

5.2.2.MEX-File function examples


5.2.2.1.Where can I get C MEX-file function examples? Aside from the many C MEX-file examples, which can be found in the $MATLAB/exter/src directory, other examples can be found in pub/tech-support/tech-notes/mxeng3.txt. and
pub/tech-support/tech-notes/mxeng4.txt.

5.2.2.2.Are there any FORTRAN MEX-file examples? There are many FORTRAN MEX-file examples which can be found in the $MATLAB/exter/src directory. 5.2.2.3. How do I write a C++ MEX-file function? A descripton of how to create C++ MEX-file functions is in a technical note which can be found on the ftp server in pub/tech-support/tech-notes/mxeng5.txt. 5.2.2.4.Are there any engine examples? The following is an example of a program that uses the MATLAB Engine to find the Hankel matrix:
#include <stdio.h> #include "engine.h" int main( void ) { Engine * ep; char * buffer; double userdata[3]; int i; for (i=0;i<3;i++) { printf("Enter element #%d: ",i+1); scanf("%lf",&userdata[i]); } ep=engOpen("setenv DISPLAY puff:0; matlab"); if(ep==NULL) { fprintf(stderr,"Error opening MATLAB"); exit(-1); } if engPutFull(ep,"mystuff",1,3,userdata,NULL) fprintf(stderr,"Error entering data into MATLAB"); buffer=mxCalloc(201,sizeof(char)); engOutputBuffer(ep,buffer,200);

if(engEvalString("hankel(mystuff)")) fprintf(stderr,"Error using hankel"); else printf("Hankel Matrix was \n%s\n",buffer); mxFree(buffer); engClose(ep); }

5.2.3. Common Problems


5.2.3.1. Why an I getting a segmentation violation error? Segmentation violation errors occur when MATLAB tries to write to an area of memory that is not allowed. Some possible causes of this are improper dereferencing of pointers, use of pointers which contain incorrect values, and writing past the end of a dimensioned array. You should check your MEX-file function to see if any of these possibilities are occurring.