| Upgrading from MATLAB 4 to MATLAB 5.0 | Search  Help Desk |
New and Enhanced Handle Graphics Features
MATLAB 5.0 provided significant improvements to Handle Graphics. For details on MATLAB graphics features, see Using MATLAB Graphics.Plotting Capabilities
MATLAB's basic plotting capabilities have been improved and expanded in MATLAB 5.0.Filling Areas
Thearea function plots a set of curves and fills the area beneath the curves.
Bar Chart Enhancements
bar3, bar3h, and barh draw vertical and horizontal bar charts. These functions, together with bar, support multiple filled bars in grouped and stacked formats.
Labels for Patches and Surfaces
legend can label any solid-color patch and surface. You can now place legends on line, bar, ribbon, and pie plots, for example.| Function |
Description |
box |
Axes box. |
datetick |
Display dates for axes tick labels. |
Marker Style Enhancement
A number of new line markers are available, including, among others, a square, a diamond, and a five-pointed star. These can be specified independently from line style.Stem Plot Enhancements
stem and stem3 plot discrete sequence data as filled or unfilled stem plots.
Three-Dimensional Plotting Support
quiver3 displays three-dimensional velocity vectors with (u,v,w) components. The ribbon function displays data as three-dimensional strips.| Function |
Description |
quiver3 |
Three-dimensional quiver plot. |
ribbon |
Draw lines as 3-D strips. |
stem3 |
Three-dimensional stem plot. |
Data Visualization
MATLAB 5.0 introduced many new and enhanced capabilities for data visualization.New Viewing Model
Axes camera properties control the orthographic and perspective view of the scene created by an axes and its child objects. You can view the axes from any location around or in the scene, as well as adjust the rotation, view angle, and target point.New Method for Defining Patches
You can define a patch using a matrix of faces and a matrix of vertices. Each row of the face matrix contains indices into the vertex matrix that define the connectivity of the face. Defining patches in this way reduces memory consumption because you no longer need to specify redundant vertices.Triangular Meshes and Surfaces
The new functionstrimesh and trisurf create triangular meshes and surfaces from x, y, and z vector data and a list of indices into the vector data.| Function |
Description |
trisurf |
Triangular surface plot. |
trimesh |
Triangular mesh plot. |
Improved Slicing
slice now supports an arbitrary slicing surface.
Contouring Enhancements
The contouring algorithm now supports parametric surfaces and contouring on triangular meshes. In addition,clabel rotates and inserts labels in contour plots.| Function |
Description |
contourf |
Filled contour plot. |
New zoom Options
Thezoom function supports two new options:
scale_factor - zooms by the specified scale factor relative to the current zoom state (e.g., zoom(2) zooms in by a factor of two).
fill - zooms to the point where the objects contained in the axes are as large as they can be without extending beyond the axes plot box from any view. Use this option when you want to rotate the axes without seeing an apparent size change.
Graphics Presentation
MATLAB 5.0 provided improved control over the display of graphics objects.Enhancements to Axes Objects
MATLAB 5.0 added more advanced control for three-dimensional axes objects. You can control the three-dimensional aspect ratio for the axes' plot box, as well as for the data displayed in the plot box. You can also zoom in and out from a three-dimensional axes using viewport scaling and axes camera properties. Theaxis command supports a new option designed for viewing graphics objects in 3-D:
axis vis3dThis option prevents MATLAB from stretching the axes to fit the size of the Figure window and otherwise altering the proportions of the objects as you change the view. In a two-dimensional view, you can display the x-axis at the top of an axes and the y-axis at the right side of an axes.
Color Enhancements
colordef white or colordef black changes the color defaults on the root so that subsequent figures produce plots with a white or black axes background color. The figure background color is changed to be a shade of gray, and many other defaults are changed so that there will be adequate contrast for most plots. colordef none sets the defaults to their MATLAB 4 values. In addition, a number of new colormaps are available.| Function |
Description |
colordef |
Select figure color scheme. |
Text Object Enhancements
MATLAB 5.0 supports a subset of TeX commands. A single text graphics object can support multiple fonts, subscripts, superscripts, and Greek symbols. See thetext function in the online MATLAB Function Reference for information about the supported TeX subset.
You can also specify multiline character strings and use normalized font units so that text size is a fraction of an axes' or uicontrol's height. MATLAB supports multiline text strings using cell arrays. Simply define a string variable as a cell array with one line per cell.
Improved General Graphics Features
The MATLAB startup file sets default properties for various graphics objects so that new figures are aesthetically pleasing and graphs are easier to understand.| Command |
Description |
dialog |
Create a dialog box. |
Figure MenuBar 'figure' is now supported on UNIX.
Lighting
MATLAB added support for a new graphics object called a light. You create a light object using thelight function. Three important light object properties are:
Color - the color of the light cast by the light object
Style - either infinitely far away (the default) or local
Position - the direction (for infinite light sources) or the location (for local light sources)
AmbientStrength, DiffuseStrength, and SpecularStrength control the intensity of the respective light-reflection characteristics; SpecularColorReflectance and SpecularExponent provide additional control over the reflection characteristics of specular light.
The Axes AmbientLightColor property determines the color of the ambient light, which has no direction and affects all objects uniformly. Ambient light effects occur only when there is a visible light object in the axes.
The light object's Color property determines the color of the directional light, and its Style property determines whether the light source is a point source (Style set to local), which radiates from the specified position in all directions, or a light source placed at infinity (Style set to infinite), which shines from the direction of the specified position with parallel rays.
You can also select the algorithm used to calculate the coloring of the lit objects. The patch and surface EdgeLighting and FaceLighting properties select between no lighting, and flat, Gouraud, or Phong lighting algorithms.
print Command Revisions
Theprint command was extensively revised for MATLAB 5.0. Consult Using MATLAB Graphics for a complete description of print command capabilities. Among the new options available for MATLAB 5.0:
-loose option makes the PostScript bounding box equal to the figure's PaperPosition property. EPSI (X Window systems) previews are the same size as the generated PostScript drawing.
-dmeta option now supports Enhanced Windows Metafiles.
print -dmfile generates an M-file that recreates a figure.
-noui option. In earlier versions of MATLAB, uicontrols did not appear when you printed figures. If you specify the -noui option with the print command, MATLAB ignores uicontrols and prints only axes and axes children.
Additional print Device Options
Theprint command has several new device options.Image Support
MATLAB 5.0 made a number of enhancements to image support. These enhancements include:Truecolor
In addition to indexed images, in which colors are stored as an array of indices into a colormap, MATLAB 5.0 now supports truecolor images. A truecolor image does not use a colormap; instead, the color values for each pixel are stored directly as RGB triplets. In MATLAB, theCData property of a truecolor image object is a three-dimensional (m-by-n-by-3) array. This array consists of three m-by-n matrices (representing the red, green, and blue color planes) concatenated along the third dimension.
Reading and Writing Images
Theimread function reads image data into MATLAB arrays from graphics files in various standard formats, such as TIFF. You can then display these arrays using the image function, which creates a Handle Graphics image object. You can also write MATLAB image data to graphics files using the imwrite function. imread and imwrite both support a variety of graphics file formats and compression schemes.
8-Bit Images
When you read an image into MATLAB usingimread, the data is stored as an array of 8-bit integers. This is a much more efficient storage method than the double-precision (64-bit) floating-point numbers that MATLAB typically uses.
The Handle Graphics image object has been enhanced to support 8-bit CData. This means you can display 8-bit images without having to convert the data to double precision. MATLAB 5.0 also supports a limited set of operations on these 8-bit arrays. You can view the data, reference values, and reshape the array in various ways. To perform any mathematical computations, however, you must first convert the data to double precision, using the double function.
Note that, in order to support 8-bit images, certain changes have been made in the way MATLAB interprets image data. This table summarizes the conventions MATLAB uses:Indexed Images
In an indexed image of classdouble, the value 1 points to the first row in the colormap, the value 2 points to the second row, and so on. In a uint8 indexed image, there is an offset; the value 0 points to the first row in the colormap, the value 1 points to the second row, and so on. The uint8 convention is also used in graphics file formats, and enables 8-bit indexed images to support up to 256 colors. Note that when you read in an indexed image with imread, the resulting image array is always of class uint8. (The colormap, however, is of class double; see below.)
If you want to convert a uint8 indexed image to double, you need to add 1 to the result. For example:
X64 = double(X8) + 1;To convert from
double to uint8, you need to first subtract 1, and then use round to ensure all the values are integers:
X8 = uint8(round(X64 - 1));The order of the operations must be as shown in these examples, because you cannot perform mathematical operations on
uint8 arrays.
When you write an indexed image using imwrite, MATLAB automatically converts the values if necessary.
Colormaps
Colormaps in MATLAB are alwaysm-by-3 arrays of double-precision floating-point numbers in the range [0, 1]. In most graphics file formats, colormaps are stored as integers, but MATLAB does not support colormaps with integer values. imread and imwrite automatically convert colormap values when reading and writing files.
Truecolor Images
In a truecolor image of classdouble, the data values are floating-point numbers in the range [0, 1]. In a truecolor image of class uint8, the data values are integers in the range [0, 255].
If you want to convert a truecolor image from one data type to the other, you must rescale the data. For example, this call converts a uint8 truecolor image to double:
RGB64 = double(RGB8)/255;This call converts a
double truecolor image to uint8:
RGB8 = uint8(round(RGB*255));The order of the operations must be as shown in these examples, because you cannot perform mathematical operations on
uint8 arrays. When you write a truecolor image using imwrite, MATLAB automatically converts the values if necessary.