1/23/2024 0 Comments Introduction to matlab course![]() ![]() We will demonstrate the process of creating and running a script below. This m-file can be reused such as in a loop, in multiple sections of an application, or in different applications. The commands in the file are executed in turn. To run it, just enter the file name at the > prompt without. Changes to the procedure can be made more easily with a file than re-typing from scratch. % b~=0 needed everywhere to ensure matched array shape/sizeįor operations that are not exploratory in nature or requiring more than a handful of commands to accomplish, it is often more practical to save the operational procedure into an m-file, which is a file with. If (b(i,j) ~= 0) then % if b(i,j) not equals 0 a = rand(4,3) b = rand( size(a)) c = zeros( size(b)) ī(1,3) = 0 b(3,2) = 0 % reset 2 specific elements of b to 0 For those situations, c is to be set to 0. The purpose is to compute elemental division with the denominator matrix having zeroes. Note that the long form of the above expression is L = A > 0.5 % L is logical array L(i,j) = 1 for all A(i,j) > 0.5 0 otherwiseī(L) = 2 % B(i,j) = 2 whenever L(i,j) = 1 (i.e., true) ![]() A = rand(3) % A is a 3x3 random number double arrayī = zeros(3) % Initialize B as a 3x3 array of zeroesī(A > 0.5) = 2 % for all A(i,j) > 0.5, set B(i,j) to 2 > disp(sprintf('This string consists of characters & numbers: %d\n', n))Ī(i,j) = rand % use rand to generate a random numberī(i,j) = 2 % set b(i,j) to 2 whenever the condition a(i,j) > 0.5 is satisfiedĮquivalent vector operations. More generally, use sprintf > help sprintf % for details %d is format for integers %f for decimal numbers > str = sprintf('This string consists of characters & numbers: %d\n', n) > disp(S) % or replace S with the string it represents This string consists of characters and numbers like: 12 In the above, num2str must be used to convert n, a double, to string forĭata type consistency. This string consists of characters and numbers like: 12 %, concatenates horizontally (new columns) X =įorm “composite” string with brackets > n=12 S = Reserved Characters : ( ) > x = 1:2:9 % define vector x with : operator (begin:interval:end) x =ġ 3 5 7 9 > y = 3:5 % interval is defaulted to 1 same as y = 3:1:5 y =ģ 4 5 > X = % 2D array. > doc sin % spawns a new document window with details on sin > quit % quits MATLAB (also exit) > lookfor cosine % if you don't know the function name acos - Inverse cosine, result in radians.Īcosd - Inverse cosine, result in degrees. > help sin % if you know function name but not it's usage SIN Sine of argument in radians. > help elfun % lists elementary math functions Elementary math functions. Matlab/elfun - Elementary math functions. Matlab/randfun - Random matrices and random streams. Matlab/elmat - Elementary matrices and matrix manipulation. Matlab/lang - Programming language constructs. Matlab/ops - Operators and special characters. Matlab/general - General purpose commands. > help % lists available packages/toolboxes. When you are ready to start writing your own code, you may want to take advantage of this to document your own code wherever appropriate to make clear your intentions for future reference. Throughout this tutorial, we will use this ( %) inline comment feature to explain the meaning or purposes of the commands. > version % this tells you the running MATLAB version ans = Output, if any, appears after the the command is entered. Note that all typed characters to the right of the % symbol are treated as explanations or documentation for the line. ![]() The example below demonstrates the use of a MATLAB utility function called version to query the current version of MATLAB you are using on this computer. Start using MATLAB by entering MATLAB commands at >. In either case, a MATLAB command window appears, along with a > prompt. To start MATLAB in Linux: enter matlab at the system prompt of a X-Forwarding window scc1% matlab &.To start MATLAB in Windows: double click the desktop MATLAB icon. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |