Vous êtes sur la page 1sur 3

Commands and subtopics of Operation on arrays o eye() , ones() , zeros() o max() , min() , absolute() o linspace() , length() o det(M) % determinant

t of matrix M o inv(M) % inverse of matrix M o : and . notation o end % last element of any array, e.g. x(1,1:end) contains the first row of x o % transpose of an array o num2str() % converts a numeric variable to string variable/character array o strcat(s1,s2,) % concatenates the strings s1,s2, o c=cell(n1,n2) % defines a cell array of dimensions n1 X n2. use c{i,j} to access the ith and jth element of the cell array c Loops o o o o if/elseif/else for while Nested loops

Importing data o xlsread() o importfile() illustration % see the attached m-file for

Plotting o figure % opens a blank figure o plot(x,y,--r) % dashed lines in red color , plot(x,y,*,MarkerSize,6) % no lines but markers of type * of size 6 o subplot(2,1,1) % points to the 1st plot of the 2 plots to be plotted in rows o hold on % to add plots to the same figure o hold off % to invalidate hold on command, if executed o title(titlename,FontSize,14) , xlabel(xlabelname,FontSize,14), ylabel() o legend(s1,s2,) % creates a legend and assigns the names s1,s2, to the plots(assuming more than 1) of figure in the same order in which they are plotted ; s1,s2, are string variables o saveas(gcf,filenamewithextension) % extension recommended .emf

Functions o function [ov1,ov2,] = function_name(iv1,iv2,) % iv1,iv2, are input variable and ov1,ov2, are output variables of the user-defined function function_name Temporary variables defined in the function are not created in the workspace Variables in the workspace cannot be directly accessed by the function unless being explicitly called in input arguments

o Script files can create/access/change variables in/of workspace and can be saved with any valid name

can also call any user-defined function or another script file defined in the current workspace

o Subfunctions Variables defined in the main function can be accessed directly from within any subfunction Variables defined in the subfunctions cannot be accessed by the main function Care should be taken to not define variables having same name in the function and its subfunction unless required to do so. Subfunctions of a particular function cannot be called directly from either a script file or some other M-file (another function file)

General commands o clc % clears the command window o clear % removes all variables from the current workspace o clear x y z % removes variables x, y, z from the current workspace o clc and clear can be used even in the script files o trapz(x,y) % computes the integral of y data w.r.t x data using the trapezoidal rule ; both x and y should be of same length

Vous aimerez peut-être aussi