Matlab-Matrix – Transpose

Matlab-Matrix – Transpose ”; Previous Next The transpose operation switches the rows and columns in a matrix. It is represented by a single quote(”). Example Consider following example − a = [ 10 12 23 ; 14 8 6; 27 8 9] b = a” Output The execution in MATLAB gives the following output − >> a = [ 10 12 23 ; 14 8 6; 27 8 9] b = a” a = 10 12 23 14 8 6 27 8 9 b = 10 14 27 12 8 8 23 6 9 >> The transpose() function You can also make use of the transpose() function to get the transpose of a matrix. Example Consider the following example for use of transpose() function − a = [ 10 12 23 ; 14 8 6; 27 8 9] b = transpose(a) Output You will get the following output − >> a = [ 10 12 23 ; 14 8 6; 27 8 9] b = transpose(a) a = 10 12 23 14 8 6 27 8 9 b = 10 14 27 12 8 8 23 6 9 >> Print Page Previous Next Advertisements ”;

Matlab-Matrix – Rank

Matlab-Matrix – Rank ”; Previous Next The rank of the matrix is the number of linearly independent columns in a matrix. The function rank() helps to return the rank of a given matrix. Example Consider following example for the use of rank() function for a matrix − a = [ 1 2 3; 2 3 4; 1 2 5] test = rank(a) Output The output in MATLAB on execution of the code is as follows − >> a = [ 1 2 3; 2 3 4; 1 2 5] test = rank(a) a = 1 2 3 2 3 4 1 2 5 test = 3 >> Print Page Previous Next Advertisements ”;

Matlab-Matrix – Matrix Determinant

Matlab-Matrix – Determinant ”; Previous Next Determinant of a matrix is calculated by using the det function of MATLAB. For example, the determinant of a matrix A is given by det(A). Example Consider following example for calculating the determinant of a matrix − a = [ 1 2 3; 2 3 4; 1 2 5]; test = det(a) Output The code on execution in MATLAB is as follows − >> a = [ 1 2 3; 2 3 4; 1 2 5]; test = det(a) test = -2 >> Print Page Previous Next Advertisements ”;

Matlab-Matrix – Home

Matlab-Matrix Tutorial PDF Version Quick Guide Resources Job Search Discussion MATLAB is a programming language developed by MathWorks. It started out as a matrix programming language where linear algebra programming was simple. It can be run both under interactive sessions and as a batch job. This tutorial gives you aggressively a gentle introduction of MATLAB programming language. It is designed to give students fluency in MATLAB programming language. Problem-based MATLAB examples have been given in simple and easy way to make your learning fast and effective. Audience This tutorial has been prepared for the beginners to help them understand basic to advanced functionality of MATLAB. After completing this tutorial you will find yourself at a moderate level of expertise in using MATLAB from where you can take yourself to next levels. Prerequisites We assume you have a little knowledge of any computer programming and understand concepts like variables, constants, expression, statements, etc. If you have done programming in any other high-level programming language like C, C++ or Java, then it will be very much beneficial and learning MATLAB will be like a fun for you. Print Page Previous Next Advertisements ”;

Matlab-Matrix – Create Matrix

Matlab-Matrix – Create a Matrix ”; Previous Next In MATLAB, you can create a matrix by entering the elements in each row as comma. You can also create a matrix with space delimited numbers and by using the semicolons to mark the end of each row. Matrix with single row Let us create a simple matrix in MATLAB that has a single row and three elements. Each element should have a space or comma. Example Consider the below mentioned elements to create a matrix. m=[2, 4, 6] Output On execution in MATLAB it will display the following − >>m = [2, 4, 6] m = 2 4 6 >> When you execute the code in MATLAB, the result of the matrix is displayed in the command window. Matrix with Multiple rows Example Let us now create a matrix with multiple rows. To do that, we need to separate each row with semicolon (;) as shown below − m = [2 4 6; 3 6 9; 4 8 12] Output Here 2 4 6 is the first row, 3 6 9 is the second row and 4 8 12 is the third row. The matrix will be as follows − m = 2 4 6 3 6 9 4 8 12 Let us now execute the same in MATLAB command prompt, as mentioned below − >> m = [2 4 6; 3 6 9; 4 8 12] m = 2 4 6 3 6 9 4 8 12 >> The 3×3 matrix is displayed as shown above in MATLAB. Besides creating matrix with the values of your choice you can also make use of the built-in MATLAB functions zeros, rand or ones to create a matrix as shown below − The zerosfunctions This will create matrix with all zeros with the given row/column size. Example You can use MATLAB zeros function as follows − m0 = zeros(3,3) Output You will get the following output − >> m0 = zeros(3,3) m0 = 0 0 0 0 0 0 0 0 0 >> The onesfunction The matrix created will have ones as the values. Example You can use MATLAB ones function as follows − m1 = ones(3,3) Output You will get the following output − >> m1 = ones(3,3) m1 = 1 1 1 1 1 1 1 1 1 >> The rand() function The function rand() allows you to create a matrix with random elements for the size given. Here is an example for the same. Example m1 = rand(3,3) Output Let us now execute the same in MATLAB to see the results. The output is as follows − >> m1 = rand(3,3) m1 = 0.8147 0.9134 0.2785 0.9058 0.6324 0.5469 0.1270 0.0975 0.9575 >> Print Page Previous Next Advertisements ”;

Matlab-Matrix – Deletion Row & Coloumn

Matlab-Matrix – Deletion of Row & Column ”; Previous Next You can delete an entire row or column of a matrix by assigning an empty set of square braces [] to that row or column. Basically, [] denotes an empty array. Example For example, let us delete the fourth row of a, as shown below − a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8]; a( 4 , : ) = [] Output Here is the execution of above code in MATLAB >> a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8] a( 4 , : ) = [] a = 1 2 3 4 5 2 3 4 5 6 3 4 5 6 7 4 5 6 7 8 a = 1 2 3 4 5 2 3 4 5 6 3 4 5 6 7 >> The fourth row is deleted. It displays only three rows. Example Next, let us delete the fifth column of a, as shown below − a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8] a(: , 5)=[] Output Let us see the execution of the above code in MATLAB − >> a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8] a(: , 5)=[] a = 1 2 3 4 5 2 3 4 5 6 3 4 5 6 7 4 5 6 7 8 a = 1 2 3 4 2 3 4 5 3 4 5 6 4 5 6 7 >> Print Page Previous Next Advertisements ”;

Matlab-Matrix – Environment Setup

Matlab-Matrix – Environment Setup ”; Previous Next The official website of MATLAB is https://www.mathworks.com. The following page will appear on your screen − To download MATLAB go to https://in.mathworks.com/downloads/ as shown below − MATLAB is not free to download and you need to pay for the licensed copy. Later on you can download it. A free trial version is available for which you have to create a login for your respective account. Once an account is created, they allow you to download MATLAB and also an online version for a trial of 30 days’ license. Once you are done with the creating a login from their website, download MATLAB and install on your system. Then, start MATLAB or you can also make use of their online version that will be available once you sign in. This is how the UI interface of MATLAB looks like when you install matlab or hit the online link of MATLAB. Understanding the MATLAB Environment MATLAB development IDE can be launched from the icon created on the desktop. The main working window in MATLAB is called the desktop. When MATLAB is started, the desktop appears in its default layout. As I said earlier if you are using the trial version can make use of the online link of MATLAB to get the IDE as shown below − Let us understand the MATLAB IDE. Current Folder This panel allows you to access the project folders and files. Command Window This is the main area where commands can be entered at the command line. It is indicated by the command prompt (>>). Workspace The workspace shows all the variables created and/or imported from files. Print Page Previous Next Advertisements ”;