Interactive figures defined in SQ files and SQ scripts rely on special functions which describe precisely which element the user maniulates and where. For more informations, you should read the chapters SQ Files References and SQ Script References.
Determine whether the SQ script is run for the first time.
b = firstrun
firstrun returns true if the SQ script is run for the first time after loading or reset, or false otherwise. For SQ scripts with interactive graphics, it should be used to give an initial value to variables which can later be manipulated by the user.
firstrun must not be used in SQ files.
The following SQ script initializes variable x only once to random values; then the user can manipuate each point interactively.
if firstrun x = rand(1,10); end if _id == 1 x(_ix) = _y1; end plot(1:10, x, '', 1);
Displacement between current and previous position during a manipulation.
dx = _dx dy = _dy dz = _dz
When the button of the mouse is held down, _dx gives the horizontal displacement from the previous to the current position of the mouse; it is equivalent to _x1-_x. _dy give the vertical displacement. _dz give both displacements as a complex number.
_x, _y, _y, _x1, _y1, _y1, _kx, _ky, _kz
ID of the manipulated graphics object.
n = _id
When a graphics object drawn with an ID argument larger than zero is manipulated with the mouse, _id gives its ID; in all other cases, _id is the empty array [].
if firstrun y = 3; x = 2; end switch _id case 1 % the horizontal line is being manipulated y = _y1; case 2 % the vertical line is being manipulated x = _x1; end line([0,1], y, 'b', 1); line([1,0], x, 'r', 2);
Index of the manipulated graphical element.
n = _ix
When a graphical object drawn with an ID argument larger than zero is manipulated with the mouse, _ix gives the index of the point being manipulated; in all other cases, _ix is the empty array [].
if firstrun y = rand(1,10); end if ~isempty(_ix) y(_ix) = _y1; end plot(y, 'g', 1);
Ratio between current and previous position during a manipulation.
kx = _kx ky = _ky kz = _kz
When the button of the mouse is held down, _kx gives the ratio between the horizontal position of the mouse and the previous horizontal position; it is equivalent to _x1/_x. _kx is typically used to change a scale or a gain. _ky does the same vertically, and _kz for both directions as a complex number.
if firstrun num = 1; den = [1,2,3,4]; end if ~isempty(_ky) % change the gain of the transfer function num/den num = _ky * num; end step(num,den,'b',1);
_x, _y, _z, _x1, _y1, _z1, _dx, _dy, _dz
Number of the manipulated trace.
n = _nb
When a graphical object drawn with an ID argument larger than zero is manipulated with the mouse, _nb gives the number of the trace being manipulated; in all other cases, _ix is the empty array [].
if firstrun Y = rand(5,10); end if ~isempty(_nb) Y(_nb,_ix) = _y1; end plot(Y, 'b', 1);
State of the Shift key during a manipulation.
b = _m
During a manipulation with the mouse, _m is true if the Shift key is held down or false otherwise.
Plot-specific value.
q = _q
When a graphical object drawn with an ID argument larger than zero is manipulated with the mouse, _q gives a value which depends on the graphics; in all other cases, _ix is the empty array []. Not all graphics define a value for _q.
Root locus where the closed-loop and open-loop poles may be manipulated:
if firstrun % define an initial transfer function num = -1; den = 1:4; end switch _id case 1 % gain change num = num * _q; case 2 % new location of open-loop poles den = movezero(den, _z0, _z1); end scale('equal',[-3,1,-2,2]); sgrid; % root locus for a gain >= 0 rlocus(num,den,'r',1); % closed-loop poles on the root locus plotroots(addpol(num,den),'^',1); % open-loop poles (gain=0) plotroots(den, 'x', 2);
Mouse position in polar coordinates when the button was pressed.
rho = _rho theta = _theta
When the button of the mouse is held down, _rho and _theta give the position at the instant when the button was pressed in polar coordinates, i.e. _rho is sqrt(_x^2+_y^2) and _theta is atan2(_y,_x). In all other cases, they return the empty array [].
_x, _y, _z, _rho0, _theta0, _rho1, _theta1
Initial position of the object being manipulated in polar coordinates.
rho = _rho0 theta = _theta0
When the button of the mouse is held down over a graphical object drawn with an ID argument larger than zero, _rho0 and _theta0 give its initial position in polar coordinates, i.e. _rho0 is sqrt(_x0^2+_y0^2) and _theta0 is atan2(_y0,_x0). In all other cases, they return the empty array [].
_x0, _y0, _z0, _rho, _theta, _rho1, _theta1
Current position of the mouse in polar coordinates during a manipulation.
rho = _rho1 theta = _theta1
When the button of the mouse is held down, _rho and _theta give the current position of the mouse in polar coordinates, i.e. _rho1 is sqrt(_x1^2+_y1^2) and _theta1 is atan2(_y1,_x1). In all other cases, they return the empty array [].
_x1, _y1, _z1, _rho0, _theta0, _rho, _theta
Current string parameter during a manipulation.
s = _str1
_str1 gives the new string value of a textfield. It is typically used in the mousedrag handler, like _x1 for numeric textfield values, even if it is not related to mouse operations.
Values of SQ variables.
v = _v
In a handler, _v gives a structure whose fields contain the value of SQ variables.
Mouse position when the button was pressed.
x = _x y = _y z = _z
When the button of the mouse is held down, _x gives the horizontal position at the instant when the button was pressed; in all other cases, _x is the empty array []. _y gives the vertical position; _z gives the horizontal and vertical position as a complex number.
% define a region where the user can click scale([0,10,0,10]); if ~isempty(_x) % draws a line between the mousedown position % and the current position plot([_x,_x1],[_y,_y1]); end
Initial position of the object being manipulated with the mouse.
x = _x0 y = _y0 z = _z0 p = _p0
When the button of the mouse is held down over a graphical object drawn with an ID argument larger than zero, _x0 gives its initial horizontal position; in all other cases, _x0 is the empty array []. _y0 gives the vertical position; _z0 gives the horizontal and vertical position as a complex number; and _p0 gives the position as a 2D vector for 2D graphics and as a 3D vector for 3D graphics.
_x, _y, _z, _x1, _y1, _z1, _p1
Current position of the mouse during a manipulation.
x = _x1 y = _y1 z = _z1 p = _p1
When the button of the mouse is held down, _x1 gives the current horizontal position of the mouse; otherwise (when the button is up), _x1 is the empty array []. _y1 gives the vertical position; _z1 gives the horizontal and vertical position as a complex number; and _p1 gives the position as a 2D vector for 2D graphics and as a 3D vector for 3D graphics, using the associated surface set by sensor3.