The MathWorks Digest August 1, 1993 Volume 1, number 1 ===================== Table of Contents ===================== o Greeting from Cleve Moler o Anonymous FTP site o MATLAB conference o MATLAB-based textbooks o Comp.soft-sys.matlab o Drea's Desk -- Using UIcontrols o Q & A o Including MATLAB graphs in documents o Missing data o Vertical sliders o Ghost in the machine The MathWorks Digest is a monthly electronic newsletter sent to subscribing users. It contains articles written by MATLAB developers and MATLAB users, as well as some Q & A. Send your submissions for the digest to digest@mathworks.com. If you would like to be added or removed from the mailing list, send e-mail to subscribe@mathworks.com ----------------------------------------------------------- Greeting from Cleve Moler Hi. We're very pleased to offer three new electronic services for MATLAB/SIMULINK users. The new anonymous FTP facility allows anyone interested in MATLAB, whether or not they are a customer, to share M-files and obtain MathWorks product information via File Transfer Protocol. The internet address is ftp.mathworks.com. If you're not familiar with anonymous FTP, see the introduction later in this Digest. The FTP Update service has been in operation for several weeks. MathWorks customers who already have licenses for products on UNIX workstations can obtain updated releases of their software via FTP. The Update service uses the same machine and internet address, but a different (non-anonymous) login. For more information, contact your Customer Service Representative or send e-mail to service@mathworks.com. The MATLAB Digest is this electronic newsletter. We intend it to complement other publications and fora. The MathWorks Newsletter is printed quarterly and mailed to all the customers, prospects and other friends we have on our mailing list. The comp.soft-sys.matlab Internet newsgroup is a free-wheeling, unmoderated electronic discussion group that many people at MathWorks follow and participate in as individuals. We hope this Digest will be more frequent and less structured than the Newsletter, but less frequent and more structured than the newsgroup. We also intend to make the Digest available to subscribing users who do not have Internet access. The proprietor of the Digest is Drea Thomas, who recently joined the MathWorks from MIT where he was a grad student in Atmospheric Physics. He received his BS degree in physics from Cal Poly, SLO. Those of you who are following the newsgroup have probably seen his contributions there. I will be helping Drea where I can. We are excited about these new activities. Please help us to make them successful by contributing any questions, comments, news items and M-files that you think will be of interest to the MATLAB community. -- Cleve Moler moler@mathworks.com ----------------------------------------------------------- Anonymous FTP site The MathWorks is pleased to announce a new service for the MATLAB community, our anonymous ftp site - ftp.mathworks.com It is a library containing, o User contributed M/MEX-files o Digests and other Documentation o Product announcements and information o Patches and bug fixes in toolbox M-files It is also a place where MATLAB users can submit M/MEX files and other utilities and information that might be useful to others. Before submitting, however, please get the file /README.incoming Send questions, comments, or suggestions to drea@mathworks.com Beginners guide to ftp To connect to ftp.mathworks.com, ftp ftp.mathworks.com Name: <= Enter anonymous Password: <= Enter your e-mail address [At sites without domain name service, you may need to use the IP address for ftp.mathworks.com which is 144.212.100.10 ] Useful ftp commands include, dir : List files in current directory ls : List files in current directory (less verbose than dir) cd : Change directories bye : Terminate ftp session and exit get : Transfer a file to your local machine binary : Set transfer type to binary (e.g. compressed files) ascii put : Transfer a file to the remote machine (ftp.mathworks.com) A good file to get first is /README, which describes what is where. An index of all user-contributed M/MEX files is /pub/contrib/INDEX.ALL ----------------------------------------------------- MATLAB conference The first MATLAB conference will be held in Cambridge, Massachussets October 18-20, 1993. This will provide the first worldwide opportunity for MATLAB users to share collected ideas, applications, and knowledge developed over the past years, to see a wide range of exciting new developments, and to plan together for the future. Some of the world's leaders in their fields will share their knowledge and techniques in a wide variety of sessions. Over 100 users will present papers on the use of MATLAB, SIMULINK, and the MATLAB toolboxes in fields including, Chemistry, Controls, Education, Electronics, Fluid Dynamics, Image Processing, Life Sciences, Mathematics, Physics, Signal Processing, and many others. The co-founders of The MathWorks, Cleve Moler and Jack Little, will also give presentations. New products, product upgrades, and work in progress will be demonstrated, introduced, or "sneak previewed". Minicourses, in the form of a teaching laboratory, will offer attendees a first hand look at some of our recently released and upcoming products and will be taught by the product developers themselves. For more information, send your name, address, and phone number to conference@mathworks.com ----------------------------------------------------- MATLAB-based textbooks A list of MATLAB-based textbooks which have been published (or will soon be released) is available by anonymous ftp from ftp.mathworks.com in the directory /pub/doc. MATLAB-based textbooks typically include one or more of the following: MATLAB homework problems, MATLAB examples in the body of the text, or a companion diskette. If you are writing a textbook based on MATLAB, SIMULINK, or MATLAB toolboxes, please contact me so I may introduce opportunities to combine software examples with the text, provide you with trademark information, support you during the writing of your book, and promote it for MATLAB users upon its release. Also, if you know of other MATLAB-based textbooks not included on this list or if you know of others interested in writing a MATLAB-based textbook, your assistance in providing me with this information is appreciated. You may email product-related questions to info@mathworks.com, or call (508) 653-1415. Cristina Palumbo Business Development The MathWorks, Inc. (508) 653-2452 X445 fax: (508) 653-2997 email: palumbo@mathworks.com ----------------------------------------------------- comp.soft-sys.matlab Comp.soft-sys.matlab is an unmoderated USENET newsgroup where MATLAB is discussed. One of the features of the newsgroup is frequent postings by MATLAB developers and even occasional posts from the creator of MATLAB. If you receive news, look for the newsgroup under the comp hierarchy. If your site doesn't get it, ask your local news administrator. Alternately, a digest of postings to the newsgroup can be found on the anonymous ftp site (ftp.mathworks.com) in, /pub/doc/CSSM-digest/ ----------------------------------------------------- % Drea's Desk will be a regular feature of the digest. In each issue of the % digest, I'll cover a different topic of interest (hopefully) to MATLAB and % SIMULINK users. Feel free to send me ideas of topics you would like to % see covered in this column. Send them to => digest@mathworks.com Drea's Desk: Using UIcontrols The ability to add User Interface (UI) controls to MATLAB figure windows allows a great deal of flexibility in what you can do with MATLAB. Buttons, sliders, and dialog boxes can make your MATLAB application truly interactive. This article is meant to get those who have never used the new tools to try them out, and for those who have used them, to use them more efficiently. To create a uicontrol, you use the UICONTROL command. h = uicontrol('propertyname',propertyvalue, ... ) The most important property to set is the 'Style' property. That determines what type of control you are going to create. Valid properties are pushbutton, radiobutton, checkbox, slider, edit, popupmenu. See the MATLAB reference guide for detailed information on each style and other properties of uicontrol objects. The next piece of information that a uicontrol needs is what to do when it is activated. This is set with the 'Callback' property. Here is a simple example where we put a button up that reverses the y axis direction when activated, h = uicontrol('style','pushbutton','callback','set(gca,''ydir'',''reverse'')') This syntax works well for very simple callbacks, but to do more complex operations, it is best to have your callback be a function name. For instance, if we want the button to toggle the direction of the axes we could create a function, ********** toggle.m ******************* function toggle if strcmp(get(gca,'ydir'),'reverse'), set(gca,'ydir','normal'); else set(gca,'ydir','reverse'); end *************************************** and make the callback 'toggle', set(h,'callback','toggle') The advantage to making your callback a function rather than a script is that once it is called, MATLAB compiles it and stores it in memory. Subsequent calls to it are, therefore, executed faster than if it were a script which has to be interpreted each time. A common need with UIcontrols is to pass information to the callback function that isn't known when the callback is set. For instance, to create a dialog box that can be used to set the plots title, h = uicontrol('style','edit','callback','mytitle') mytitle.m will need to know the handle to the editible text box to read its value. To store this information, you can either, o Make h a global variable or o Store h in the figure windows userdata property (In this case, you have the option to set the callback after you have created the dialog box, but that is not always an option) Here is an example using the global variable technique, global h h = uicontrol('style','edit','callback','mytitle') ******** mytitle.m ******************* function mytitle global h title(get(h,'string')) ************************************** Another tip for speeding up your UIcontrols is to put all your callback functions in the same M-file. That way, once you use one of your UIcontrol objects, the M-file is compiled, and the other objects callbacks will execute without having to first compile another M-file. Here is an example that combines the toggle and mytitle functions, ********* controls ****************** function controls(n) global h if n == 1, if strcmp(get(gca,'ydir'),'reverse'), set(gca,'ydir','normal'); else set(gca,'ydir','reverse'); end elseif n == 2, title(get(h,'string')) end ************************************* Then, make your callback for the axis toggle button 'controls(1)' and for your title box 'controls(2)'. This technique can very significantly reduce the response time of UIcontrol objects, particularly when the callback functions are long. ----------------------------------------------------- % The question and answer section of the digest will contain (you guessed it), % questions from users and answers from The MathWorks or other users. This % first issue's Q & A will come from Comp.soft-sys.matlab, but if you have something % you've always wanted to ask, feel free to send it to us => digest@mathworks.com Q & A Question from: tfarrell@bbn.com (Ted Farrell) Subject: PS Conversion Needed I am trying to get postscipt files created by MATLAB 4.0a on the SUN into either MacDraw PRO or Microsoft Word on a MACII. They both seem to read EPS, but not PostScript. Is there an appropriate conversion program available? I have looked at Picture-This and it doesn't seem to have the right options. I also looked at the FAQ, and it mentions pstoepsi. Does anyone know where to get this?? ------- From: Chuck Packard Subject: Re: PS Conversion Needed There should be no problems bringing MATLAB v4 generated EPS into Word. EPS stands for Encapsulated PostScript. From the way you stated your question I wasn't sure you knew EPS _is_ PostScript. It's just a flavor of PostScrit that has a few restrictions on what commands you use so the graphic it describes can be encapsulated by a larger document (via Word or FrameMaker,etc..). You get MATLAB to produce the EPS file with the command >> print -deps filename I've never seen MacDraw Pro, but I assume it only deals with PICT files. MATLAB v4 for the Mac will produce EPS files with PICT preview resources. If you have MATLAB on some other machine but document on the Mac, there are tools mentioned in another post to this thread that produce the PICT preview. I've also written a Mac application, using Drag&Drop on System 7 or just Open in System 6, to take an EPS file with an EPSI preview (the platform independent 7-bit ASCII bitmap preview that MATLAB can put in an EPS file) by using one of the commands >> print -deps -epsi filename %version 4.1 >> print -deps-preview filename %older version 4's It reads in the bitmap and produces a PICT bitmap in the resource fork (I'm thinking of modifying so it deletes the now useless EPSI preview). This gives you a preview in Pagemaker and other applications. It also allows you to use PowerPoint which _requires_ a PICT preview before it will import EPS files. % epsi2pict is available via anonymous ftp from ftp.mathworks.com as, % /pub/contrib/tools/epsi2pict.tar ------ Answer From: woodford@fourier.ece.cmu.edu (Paul Woodford) Another option is ps2eps-mac, which is available via AFS from /afs/umich.edu/group/itd/archive/mac/util/unix or by anonymous ftp from mac.archive.umich.edu (I think). It requires ghostscript. The first part of the man page follows. NAME ps2eps-mac - converts arbitrary single page PostScript images to Mac- Binary EPS with PICT preview --------------------------------------------------------- Question From: srobeson@nickel.ucs.indiana.edu (scott robeson) Subject: Missing data convention Does Matlab have a convention for missing data? For plotting, it would be particularly nice to just skip over missing elements in a matrix. Most of us have problems with missing data, so I would imagine that someone has come across this on before. I don't want to interpolate, just "pick up the pen" and move on. ----- Answer From: Damian T. Packer Subject: Re: Missing data convention Putting a NaN in the x, y, or z data of a curve object has the effect you're looking for - that point (for lack of a better word) isn't drawn, and data points on either side are not connected by line segments. try this variation on plot(1:10) to see the results: plot([1:4, nan, 6:10]) Nans can also provide useful effects when slipped into the x, y, or z data of a surface object - all faces and edges that share that vertex are not drawn. For a demo, try p = surf(peaks); x = get(p,'xdata'); x2 = x; x2(2:3:49) = nan * ones(size(2:3:49)); set(p,'xdata',x2) This draws only every third row of faces across a peaks surface, and is a nice effect, if you need to see something through the surface, or if you need a break from real work... Now I can't guarantee that its an *official* convention, although "Not a Number" seems to express the concept of missing data pretty well. -damian --------------------------------------------------------- Question from: Sverre Holm Subject: Horizontal sliders for MATLAB ver 4.0? I am using the uicontrol function to set up sliders for controlling the azimuth and elevation angles of a surface plot using surfc. It would be nice to be able to locate the slider for the azimuth angle along the horizontal axis instead of the vertical, since that corresponds to the way it affects the plot. Also I miss the possibility to label the sliders. Is this possible? I am using MATLAB ver 4 on a SUN. ----- Answer From: John Little Subject: Re: Horizontal sliders for MATLAB ver 4.0? If you set the position property of the uicontrol object (slider) to the shape you want it, the slider will automagically be oriented either horizontally or vertically depending upon its aspect ratio. You can use the "text" style of uicontrols (see the release notes) to create labels for the sliders. --------------------------------------------------------- Question From: sergeb@cco.caltech.edu (Serge J. Belongie) Subject: face appears after typing "axis(image)" Ok, Matlab 4 users... I was working with an image of Lena, and while going through the normal motions with "image" and "colormap", etc., I accidentally typed "axis(image)" instead of "axis('image')"... It complained of an error, and then when the prompt returned, a male face appeared in the figure window! I thought it had something to do with Lena, but when I quit and reloaded Matlab, it still did it. I'm using a Sparc IPX with XWindows, and all I have to do to get this face to appear is run Matlab, type "figure" and then type "axis(image)". Has this happened to anyone else? --Serge ------ From: zwork@starfighter.den.mmc.com (Michael Corvin) Subject: Re: face appears after typing "axis(image)" Yep - I just tried it in V4.0a on the Sparc - it seems a developer had some fun with error traps... Just typing "image" will also reveal the mysterious face (best viewed with "cool" colormap) since this also is an incorrect syntax. Is this The Ghost In The Machine??? Or just some guy trapped in cyberspace??? :-) ------ From: moler@MathWorks.COM (Cleve Moler) Subject: Re: face appears after typing "axis(image)" The "official" color map for viewing the V4.0 default image data is 1-gray(16). So the complete code might be: image, colormap(1-gray(16)), axis image To recover the data: D = get(get(gca,'children'),'cdata'); If you want to know why I use "D", come to the MATLAB Conference this fall, and meet "D" face-to-face, so to speak. ---------------------------------------------------------