demo edit matmanip 5*6 ans = 30 openvar('ans', ans); ans ans = 4 ans + 3 ans = 7 a= sqrt (3) a = 1.7321 openvar('ans', ans); format long a a = 1.73205080756888 help format FORMAT Set output format. FORMAT with no inputs sets the output format to the default appropriate for the class of the variable. For float variables, the default is FORMAT SHORT. FORMAT does not affect how MATLAB computations are done. Computations on float variables, namely single or double, are done in appropriate floating point precision, no matter how those variables are displayed. Computations on integer variables are done natively in integer. Integer variables are always displayed to the appropriate number of digits for the class, for example, 3 digits to display the INT8 range -128:127. FORMAT SHORT and LONG do not affect the display of integer variables. FORMAT may be used to switch between different output display formats of all float variables as follows: FORMAT SHORT Scaled fixed point format with 5 digits. FORMAT LONG Scaled fixed point format with 15 digits for double and 7 digits for single. FORMAT SHORT E Floating point format with 5 digits. FORMAT LONG E Floating point format with 15 digits for double and 7 digits for single. FORMAT SHORT G Best of fixed or floating point format with 5 digits. FORMAT LONG G Best of fixed or floating point format with 15 digits for double and 7 digits for single. FORMAT SHORT ENG Engineering format that has at least 5 digits and a power that is a multiple of three FORMAT LONG ENG Engineering format that has exactly 16 significant digits and a power that is a multiple of three. FORMAT may be used to switch between different output display formats of all numeric variables as follows: FORMAT HEX Hexadecimal format. FORMAT + The symbols +, - and blank are printed for positive, negative and zero elements. Imaginary parts are ignored. FORMAT BANK Fixed format for dollars and cents. FORMAT RAT Approximation by ratio of small integers. Numbers with a large numerator or large denominator are replaced by *. FORMAT may be used to affect the spacing in the display of all variables as follows: FORMAT COMPACT Suppresses extra line-feeds. FORMAT LOOSE Puts the extra line-feeds back in. Example: format short, pi, single(pi) displays both double and single pi with 5 digits as 3.1416 while format long, pi, single(pi) displays pi as 3.14159265358979 and single(pi) as 3.1415927. format, intmax('uint64'), realmax shows these values as 18446744073709551615 and 1.7977e+308 while format hex, intmax('uint64'), realmax shows them as ffffffffffffffff and 7fefffffffffffff respectively. The HEX display corresponds to the internal representation of the value and is not the same as the hexadecimal notation in the C programming language. See also disp, display, isnumeric, isfloat, isinteger. Reference page in Help browser doc format 55.43*10^3 ans = 55430 55.43e3 ans = 55430 55.43e-3 ans = 0.05543000000000 ans = 53423 ans = 53423 iskeyword ans = 'break' 'case' 'catch' 'continue' 'else' 'elseif' 'end' 'for' 'function' 'global' 'if' 'otherwise' 'persistent' 'return' 'switch' 'try' 'while' pi ans = 3.14159265358979 pi= 4 pi = 4 % must be careful in assignments, you can overwrite most default values clear help clear CLEAR Clear variables and functions from memory. CLEAR removes all variables from the workspace. CLEAR VARIABLES does the same thing. CLEAR GLOBAL removes all global variables. CLEAR FUNCTIONS removes all compiled M- and MEX-functions. CLEAR ALL removes all variables, globals, functions and MEX links. CLEAR ALL at the command prompt also removes the Java packages import list. CLEAR IMPORT removes the Java packages import list at the command prompt. It cannot be used in a function. CLEAR CLASSES is the same as CLEAR ALL except that class definitions are also cleared. If any objects exist outside the workspace (say in userdata or persistent in a locked m-file) a warning will be issued and the class definition will not be cleared. CLEAR CLASSES must be used if the number or names of fields in a class are changed. CLEAR JAVA is the same as CLEAR ALL except that java classes on the dynamic java path (defined using JAVACLASSPATH) are also cleared. CLEAR VAR1 VAR2 ... clears the variables specified. The wildcard character '*' can be used to clear variables that match a pattern. For instance, CLEAR X* clears all the variables in the current workspace that start with X. CLEAR -REGEXP PAT1 PAT2 can be used to match all patterns using regular expressions. This option only clears variables. For more information on using regular expressions, type "doc regexp" at the command prompt. If X is global, CLEAR X removes X from the current workspace, but leaves it accessible to any functions declaring it global. CLEAR GLOBAL X completely removes the global variable X. CLEAR GLOBAL -REGEXP PAT removes global variables that match regular expression patterns. Note that to clear specific global variables, the GLOBAL option must come first. Otherwise, all global variables will be cleared. CLEAR FUN clears the function specified. If FUN has been locked by MLOCK it will remain in memory. Use a partial path (see PARTIALPATH) to distinguish between different overloaded versions of FUN. For instance, 'clear inline/display' clears only the INLINE method for DISPLAY, leaving any other implementations in memory. CLEAR ALL, CLEAR FUN, or CLEAR FUNCTIONS also have the side effect of removing debugging breakpoints and reinitializing persistent variables since the breakpoints for a function and persistent variables are cleared whenever the m-file changes or is cleared. Use the functional form of CLEAR, such as CLEAR('name'), when the variable name or function name is stored in a string. Examples for pattern matching: clear a* % Clear variables starting with "a" clear -regexp ^b\d{3}$ % Clear variables starting with "b" and % followed by 3 digits clear -regexp \d % Clear variables containing any digits See also who, whos, mlock, munlock, persistent. Reference page in Help browser doc clear % arrays a= [1 2 3] a = 1 2 3 a= [1 2 3]' a = 1 2 3 a= [ 1; 2; 3] a = 1 2 3 B= 1:7 B = 1 2 3 4 5 6 7 B= 1:.5:7 B = Columns 1 through 4 1.00000000000000 1.50000000000000 2.00000000000000 2.50000000000000 Columns 5 through 8 3.00000000000000 3.50000000000000 4.00000000000000 4.50000000000000 Columns 9 through 12 5.00000000000000 5.50000000000000 6.00000000000000 6.50000000000000 Column 13 7.00000000000000 B(1,4) ans = 2.50000000000000 A= [1 2 3; 4 5 6] A = 1 2 3 4 5 6 A(2,:) ans = 4 5 6 openvar('A', A); n(3,2) ??? Undefined command/function 'n'. n(3,2)=0 n = 0 0 0 0 0 0 zeros(3,2) ans = 0 0 0 0 0 0 ones(2,3) ans = 1 1 1 1 1 1 eye(3) ans = 1 0 0 0 1 0 0 0 1 eye(3,5) ans = 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 magic(4) ans = 16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1 r=rand(5,2) r = 0.95012928514718 0.76209683302739 0.23113851357429 0.45646766516834 0.60684258354179 0.01850364324822 0.48598246870930 0.82140716429525 0.89129896614890 0.44470336435319 help rand RAND Uniformly distributed pseudo-random numbers. R = RAND(N) returns an N-by-N matrix containing pseudo-random values drawn from a uniform distribution on the unit interval. RAND(M,N) or RAND([M,N]) returns an M-by-N matrix. RAND(M,N,P,...) or RAND([M,N,P,...]) returns an M-by-N-by-P-by-... array. RAND with no arguments returns a scalar. RAND(SIZE(A)) returns an array the same size as A. You can use any one of three generator algorithms, as follows: RAND(METHOD,S) causes RAND to use the generator determined by METHOD, and initializes the state of that generator. S is a scalar integer value from 0 to 2^32-1, or the output of RAND(METHOD). METHOD is one of the following strings: 'state' - Use a modified version of Marsaglia's Subtract-with-Borrow algorithm, the default in MATLAB Versions 5 and later. This method can generate all the double precision values in the closed interval [2^(-53), 1-2^(-53)], and, theoretically, can generate over 2^1492 values before repeating itself. 'seed' - Use a multiplicative congruential algorithm, the default in MATLAB Version 4. This method generates double precision values in the closed interval [1/(2^31-1), 1-1/(2^31-1)], with a period of 2^31-2. 'twister' - Use the Mersenne Twister algorithm by Nishimura and Matsumoto. This method generates double precision values in the closed interval [2^(-53), 1-2^(-53)], with a period of (2^19937-1)/2. RAND(METHOD) returns the current internal state of the generator determined by METHOD. However, it does not switch generators. The sequence of numbers produced by RAND is determined by the internal state of the generator. Setting the generator to the same fixed state allows computations to be repeated. Setting the generator to different states leads to unique computations, however, it does not improve any statistical properties. Since MATLAB resets the state at start-up, RAND will generate the same sequence of numbers in each session unless the state is changed. Note: The size inputs M, N, and P... should be nonnegative integers. Negative integers are treated as 0. Examples: Return RAND to its default initial state. rand('state',0) Initialize RAND to a different state each time. rand('state',sum(100*clock)) Save the current state, generate 100 values, reset the state, and repeat the sequence. s = rand('state'); u1 = rand(100); rand('state',s); u2 = rand(100); % contains exactly the same values as u1 Generate uniform values from the interval [a, b]. r = a + (b-a).*rand(100,1); Generate integers uniform on the set 1:n. r = ceil(n.*rand(100,1)); Use the Mersenne Twister generator, with the default initial state used by Nishimura and Matsumoto. rand('twister',5489); For a full description of the Mersenne Twister algorithm, see http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html. See also randn, sprand, sprandn, randperm. Reference page in Help browser doc rand r(10,3)=13 r = 0.95012928514718 0.76209683302739 0 0.23113851357429 0.45646766516834 0 0.60684258354179 0.01850364324822 0 0.48598246870930 0.82140716429525 0 0.89129896614890 0.44470336435319 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 13.00000000000000 % operations on arrays A*A' ans = 14 36 36 101 % element-wise A.*A' ??? Error using ==> times Matrix dimensions must agree. A.*A ans = 1 4 9 16 49 36 A+1.2 ans = 2.20000000000000 3.20000000000000 4.20000000000000 5.20000000000000 8.20000000000000 7.20000000000000 % careful w= 0:3 + 1:10 w = 0 4 8 w= 0:(3+1):10 w = 0 4 8 w=[0:3]+[1:4] w = 1 3 5 7 w.^3 ans = 1 27 125 343 who Your variables are: A B a ans n r w whos Name Size Bytes Class A 2x3 48 double array B 1x13 104 double array a 3x1 24 double array ans 1x4 32 double array n 3x2 48 double array r 10x3 240 double array w 1x4 32 double array Grand total is 66 elements using 528 bytes % plotting % suppressing input ";" % alternative to ":", linspace linspace(1,5,11) ans = Columns 1 through 4 1.00000000000000 1.40000000000000 1.80000000000000 2.20000000000000 Columns 5 through 8 2.60000000000000 3.00000000000000 3.40000000000000 3.80000000000000 Columns 9 through 11 4.20000000000000 4.60000000000000 5.00000000000000 % for 100 points, leave off the last parameter x= linspace(-2*pi, 2*pi); help plot PLOT Linear plot. PLOT(X,Y) plots vector Y versus vector X. If X or Y is a matrix, then the vector is plotted versus the rows or columns of the matrix, whichever line up. If X is a scalar and Y is a vector, length(Y) disconnected points are plotted. PLOT(Y) plots the columns of Y versus their index. If Y is complex, PLOT(Y) is equivalent to PLOT(real(Y),imag(Y)). In all other uses of PLOT, the imaginary part is ignored. Various line types, plot symbols and colors may be obtained with PLOT(X,Y,S) where S is a character string made from one element from any or all the following 3 columns: b blue . point - solid g green o circle : dotted r red x x-mark -. dashdot c cyan + plus -- dashed m magenta * star (none) no line y yellow s square k black d diamond v triangle (down) ^ triangle (up) < triangle (left) > triangle (right) p pentagram h hexagram For example, PLOT(X,Y,'c+:') plots a cyan dotted line with a plus at each data point; PLOT(X,Y,'bd') plots blue diamond at each data point but does not draw any line. PLOT(X1,Y1,S1,X2,Y2,S2,X3,Y3,S3,...) combines the plots defined by the (X,Y,S) triples, where the X's and Y's are vectors or matrices and the S's are strings. For example, PLOT(X,Y,'y-',X,Y,'go') plots the data twice, with a solid yellow line interpolating green circles at the data points. The PLOT command, if no color is specified, makes automatic use of the colors specified by the axes ColorOrder property. The default ColorOrder is listed in the table above for color systems where the default is blue for one line, and for multiple lines, to cycle through the first six colors in the table. For monochrome systems, PLOT cycles over the axes LineStyleOrder property. If you do not specify a marker type, PLOT uses no marker. If you do not specify a line style, PLOT uses a solid line. PLOT(AX,...) plots into the axes with handle AX. PLOT returns a column vector of handles to lineseries objects, one handle per plotted line. The X,Y pairs, or X,Y,S triples, can be followed by parameter/value pairs to specify additional properties of the lines. For example, PLOT(X,Y,'LineWidth',2,'Color',[.6 0 0]) will create a plot with a dark red line width of 2 points. Backwards compatibility PLOT('v6',...) creates line objects instead of lineseries objects for compatibility with MATLAB 6.5 and earlier. See also plottools, semilogx, semilogy, loglog, plotyy, plot3, grid, title, xlabel, ylabel, axis, axes, hold, legend, subplot, scatter. Overloaded functions or methods (ones with the same name in other directories) help timeseries/plot.m help wdectree/plot.m help ntree/plot.m help dtree/plot.m help wvtree/plot.m help rwvtree/plot.m help edwttree/plot.m Reference page in Help browser doc plot plot(x, sin(x)) hold on plot(x, cos(x), 'r--') plot(x, sin(x), '-or', 'linewidth', 2) title('plot of sine on [-2pi, 2pi]') xlabel('note the use of line-file And a marker') y= sin(x); plot(x,y,'kx') text(x(1), y(1), sprintf('(%g,%g)', x(1), y(1)) ??? text(x(1), y(1), sprintf('(%g,%g)', x(1), y(1)) | Error: Expression or statement is incorrect--possibly unbalanced (, {, or [. text(x(1), y(1), sprintf('(%g,%g)', x(1), y(1))) s= spline(x,y); hold on xx= linspace(min(x), max(x), 51); plot(xx, ppval(s,xx)) help spline SPLINE Cubic spline data interpolation. PP = SPLINE(X,Y) provides the piecewise polynomial form of the cubic spline interpolant to the data values Y at the data sites X, for use with the evaluator PPVAL and the spline utility UNMKPP. X must be a vector. If Y is a vector, then Y(j) is taken as the value to be matched at X(j), hence Y must be of the same length as X -- see below for an exception to this. If Y is a matrix or ND array, then Y(:,...,:,j) is taken as the value to be matched at X(j), hence the last dimension of Y must equal length(X) -- see below for an exception to this. YY = SPLINE(X,Y,XX) is the same as YY = PPVAL(SPLINE(X,Y),XX), thus providing, in YY, the values of the interpolant at XX. For information regarding the size of YY see PPVAL. Ordinarily, the not-a-knot end conditions are used. However, if Y contains two more values than X has entries, then the first and last value in Y are used as the endslopes for the cubic spline. If Y is a vector, this means: f(X) = Y(2:end-1), Df(min(X))=Y(1), Df(max(X))=Y(end). If Y is a matrix or N-D array with SIZE(Y,N) equal to LENGTH(X)+2, then f(X(j)) matches the value Y(:,...,:,j+1) for j=1:LENGTH(X), then Df(min(X)) matches Y(:,:,...:,1) and Df(max(X)) matches Y(:,:,...:,end). Example: This generates a sine-like spline curve and samples it over a finer mesh: x = 0:10; y = sin(x); xx = 0:.25:10; yy = spline(x,y,xx); plot(x,y,'o',xx,yy) Example: This illustrates the use of clamped or complete spline interpolation where end slopes are prescribed. In this example, zero slopes at the ends of an interpolant to the values of a certain distribution are enforced: x = -4:4; y = [0 .15 1.12 2.36 2.36 1.46 .49 .06 0]; cs = spline(x,[0 y 0]); xx = linspace(-4,4,101); plot(x,y,'o',xx,ppval(cs,xx),'-'); Class support for inputs x, y, xx: float: double, single See also interp1, pchip, ppval, unmkpp, mkpp, splines (The Spline Toolbox). Reference page in Help browser doc spline % M-files type mean function y = mean(x,dim) %MEAN Average or mean value. % For vectors, MEAN(X) is the mean value of the elements in X. For % matrices, MEAN(X) is a row vector containing the mean value of % each column. For N-D arrays, MEAN(X) is the mean value of the % elements along the first non-singleton dimension of X. % % MEAN(X,DIM) takes the mean along the dimension DIM of X. % % Example: If X = [0 1 2 % 3 4 5] % % then mean(X,1) is [1.5 2.5 3.5] and mean(X,2) is [1 % 4] % % Class support for input X: % float: double, single % % See also MEDIAN, STD, MIN, MAX, VAR, COV, MODE. % Copyright 1984-2005 The MathWorks, Inc. % $Revision: 5.17.4.3 $ $Date: 2005/05/31 16:30:46 $ if nargin==1, % Determine which dimension SUM will use dim = min(find(size(x)~=1)); if isempty(dim), dim = 1; end y = sum(x)/size(x,dim); else y = sum(x,dim)/size(x,dim); end help mean% For vectors, MEAN(X) is the mean value of the elements in X. For MEAN Average or mean value. For vectors, MEAN(X) is the mean value of the elements in X. For matrices, MEAN(X) is a row vector containing the mean value of each column. For N-D arrays, MEAN(X) is the mean value of the elements along the first non-singleton dimension of X. MEAN(X,DIM) takes the mean along the dimension DIM of X. Example: If X = [0 1 2 3 4 5] then mean(X,1) is [1.5 2.5 3.5] and mean(X,2) is [1 4] Class support for input X: float: double, single See also median, std, min, max, var, cov, mode. Overloaded functions or methods (ones with the same name in other directories) help timeseries/mean.m Reference page in Help browser doc mean % matrices, MEAN(X) is a row vector containing the mean value of % each column. For N-D arrays, MEAN(X) is the mean value of the % elements along the first non-singleton dimension of X. % % MEAN(X,DIM) takes the mean along the dimension DIM of X. % % Example: If X = [0 1 2 % 3 4 5] % % then mean(X,1) is [1.5 2.5 3.5] and mean(X,2) is [1 % 4] % % Class support for input X: % float: double, single % % See also MEDIAN, STD, MIN, MAX, VAR, COV, MODE. % Copyright 1984-2005 The MathWorks, Inc. % $Revision: 5.17.4.3 $ $Date: 2005/05/31 16:30:46 $ f= inline('3*x-4') f = Inline function: f(x) = 3*x-4 f(0) ans = -4 % for m-files: clear, clf, clc pwd ans = U:\ cd matlab\velocity\ ls . velocity1.m velocityClosedForm.m~ .. velocity1.m~ velocityPlot.fig velocity.m velocity2.m velocityPlot.jpg velocity.m~ velocityClosedForm.m open velocity.m help deriv deriv.m not found. Use the Help browser Search tab to search the documentation, or type "help help" for help command options, such as help for methods. velocity(2,0,12,68.1,.25) ??? Input argument "cd" is undefined. Error in ==> velocity at 22 dvdt = deriv(t, v, m, cd); velocity(2,0,12,0, 68.1,.25) The velocity is 51.6008 m/s ans = 51.60078449575725 disp(a) 1 2 3