Set the scale of the next graphics.
axis([xmin,xmax,ymin,ymax]) axis equal limits = axis
With an input argument, the axis command, which should be placed before any other graphical command, sets the scale and scale options. The parameter is either a vector of 4 elements which sets the limits of the plot for both x and y axis, or the string 'equal' to make the scale equal in both directions so that circles are really displayed as circles and not ellipses.
With an output argument, axis gives the current limits of the plot in a row vector [xmin,xmax,ymin,ymax].
Vertical bar plot.
bar(y) bar(x, y) bar(x, y, w) bar(..., kind) bar(..., kind, color)
bar(x,y) plots the columns of y as vertical bars centered around the corresponding value in x. If x is not specified, its default value is 1:size(y,2).
bar(x,y,w), where w is scalar, specifies the relative width of each bar with respect to the horizontal distance between the bars; with values smaller than 1, bars are separated with a gap, while with values larger than 1, bars overlap. If w is a vector of two components [w1,w2], w1 corresponds to the relative width of each bar in a group (columns of y), and w2 to the relative width of each group. Default values, used if w is missing or is the empty matrix [], is 0.8 for both w1 and w2.
bar(...,kind), where kind is a string, specifies the kind of bar plot. The following values are recognized:
'grouped' | Columns of y are grouped horizontally (default) |
'stacked' | Columns of y are stacked vertically |
'interval' | Same as grouped, except that bars have min and max values |
With 'interval', intervals are defined by two consecutive rows of y, which must have an even number of rows.
The optional argument color is a string made of one or several color characters:
'k' | black |
'w' | white with a black frame |
First color is applied to first row of y, second color to second row, and so on; if there are less colors than rows, colors are recycled.
bar([2,4,3,6;3,5,4,1]); % simple bar plot bar(1:4, magic(4), [], 'stacked'); % stacked bar plot bar(1:4, [2,4,3,1;5,6,4,6], [], 'interval'); % interval plot
Horizontal bar plot.
barh(x) barh(y, x) barh(y, x, w) barh(..., kind) barh(..., kind, style)
barh plots a bar plot with horizontal bars. Please see bar for a description of its behavior and arguments.
barh([2,4,3,6;3,5,4,1]); % simple bar plot barh(1:4, magic(4), [], 'stacked'); % stacked bar plot barh(1:4, [2,4,3,1;5,6,4,6], [], 'interval'); % interval plot
Play music.
beep(freq) beep([freq, duration]) beep([freq, duration, volume])
The beep command plays one or several sounds. Argument is a m-by-n matrix, with n between 1 and 3; first column is the frequency in Hertz, second column is duration in seconds (default 0.1), and third column is volume between 0 and 1 (default 1).
beep(440 * 2.^((0:12)'/12));
Clear the console (output) window.
clc clc(fd)
clc (clear console) clears the contents of the text output panel.
clc(fd) clears the contents of the text output associated with file descriptor fd.
Clear the figure window.
clf
Discard the graphics output and display the text output window.
close
Level curves.
contour(z) contour(z, [xmin, xmax, ymin, ymax]) contour(z, [xmin, xmax, ymin, ymax], levels)
contour(z) plots seven contour lines corresponding to the surface whose samples at equidistant points 1:size(z,2) in the x direction and 1:size(z,1) on the y direction are given by z. Contour lines are at equidistant levels. With a second non-empty argument [xmin, xmax, ymin, ymax], the samples are at equidistant points between xmin and xmax in the x direction and between ymin and ymax in the y direction. The optional third argument levels, if non-empty, gives the number of contour lines if it is a scalar or the levels themselves if it is a vector.
A function is evaluated over a grid of two variables x and
y, and is drawn with contour
(x, y) = meshgrid(-2 + (0:40) / 10); z = exp(-((x-0.2).^2+(y+0.3).^2)) ... - exp(-((x+0.5).^2+(y-0.1).^2)) + 0.1 * x; axis equal; contour(z, [-1,1,-1,1]);
Function plot.
fplot(fun) fplot(fun, limits) fplot(fun, limits, style) fplot(fun, limits, style, p1, p2, ...)
Command fplot(fun,limits) plots function fun, specified by its name as a string, a function reference, or an inline function. The function is plotted for x between limit(1) and limit(2); the default limits are [-5,5].
The style of the plot can be specified with a third argument (see plot for details). Remaining input arguments of fplot, if any, are given as additional input arguments to function fun. They permit to parameterize the function. For example fplot('fun',[0,10],'',2,5) calls fun as y=fun(x,2,5) and displays its value for x between 0 and 10.
Plot a sine:
fplot(@sin);
Plot
fun = inline('function y=f(x,a); y=(x+0.3)^2+a*exp(-3*x^2);'); fplot(fun, [-2,3], 'r', 7.2);
plot, hold, clf, inline, operator @
Graphic freeze.
hold on hold off
Command hold controls whether the graphics window is cleared before graphical commands such as plot and text display new elements. hold on suspends the auto-clear feature, and hold off resumes it. In any case, clf always resumes it.
t = 0:0.1:2*pi; plot(t, sin(t)); hold on; plot(t, cos(t)); hold off; pause(3); plot(t, sin(t).*cos(t));
Image plot.
image(A)
image(A) displays array A as an image. A is an array of two dimensions for grayscale images or three dimensions for RGB images, with size(A,3)==3. image accepts different types of data: double arrays must contain numbers between 0 for black and 1 for maximum intensity; uint8 arrays contain numbers between 0 for black and 255 for maximum intensity; and logical arrays contain false for black and true for maximum intensity. Function map2int is useful for converting double values in other ranges.
The image is displayed as a low density bitmap, centered in the graphics area. The first value in the array corresponds to the top left corner.
image requires Palm OS 4.0 or higher.
x = meshgrid(-2:0.1:2); % coord for x (y is x.') A = cos(x.^2 + x.'.^2); % cos(r^2), element-wise image(map2int(A, -1, 1)); % double [-1,1] to uint8
Generic plot with a logarithmic scale along x and y axis.
loglog(y) loglog(x, y) loglog(x, y, style)
Command loglog is similar to plot, except that the scale along both x and y axis is logarithmic.
plot, semilogx, semilogy, hold, clf
Put the handheld in low power mode.
pause(t)
pause(t) makes the handheld wait for t seconds in low-power mode.
Generic plot.
plot(y) plot(x, y) plot(x, y, style)
Command plot displays graphical data. The data are given as two vectors of coordinates x and y. Depending on the style, the points are displayed as individual marks (style = 'x', 'o', or '.') or are linked with lines (style = '-'). The style may also specify the color:
Color | Character |
---|---|
black | k |
blue | b |
green | g |
cyan | c |
red | r |
magenta | m |
yellow | y |
white | w |
The default style is '-'.
If x and y are matrices, each row is considered as a separate line or set of marks; if only one of them is a matrix, the other one, a vector, is reused for each line. The style string may contain several styles which are used for each line, and recycled if necessary.
The first argument x may be omitted; its default value is 1:size(y,2).
Plot a sine in black and a cosine in light blue:
t = 0:0.1:2*pi; plot(t,[sin(t); cos(t)], 'kc');
semilogx, semilogy, loglog, polar, fplot, hold, clf
Polar plot.
polar(phi, r) polar(phi, r, style)
Command polar displays graphical data in polar coordinates. The data are given as two vectors of polar coordinates phi and r; their corresponding Cartesian coordinates are x=r*cos(phi) and y=r*sin(phi). Several polar plots may be combined with hold; however, other kinds of plots should not be mixed.
If phi and r are matrices, each row is considered as a separate line or set of marks. Unlike plot, both matrices must have the same size.
See the description of plot for more information about the third argument.
phi = 2*pi*(0:100)/100; polar(phi, 2+cos(5*phi), 'r');
Generic plot with a logarithmic scale along x axis.
semilogx(y) semilogx(x, y) semilogx(x, y, style)
Command semilogx is similar to plot, except that the scale along the x axis is logarithmic.
plot, semilogy, loglog, hold, clf
Generic plot with a logarithmic scale along y axis.
semilogy(y) semilogy(x, y) semilogy(x, y, style)
Command semilogy is similar to plot, except that the scale along the y axis is logarithmic.
plot, semilogx, loglog, hold, clf
Display formatted text in a figure.
text(x, y, string)
text displays a string centered at the specified position. Function sprintf can be used to create a string and display numbers.
The following code displays the string (1.2,3.7) centered around these coordinates.
x = 1.2; y = 3.7; text(x, y, sprintf('(%.1f,%.1f)', x, y));