How To Interchange a ROW OR COLUMN of Two Matrix in MATLAB

Previously we discussed about How to interchange a single element of two matrices in MATLAB. Now in Post-10 of Module-01, we will discuss, how to interchange a row/column of two matrix in MATLAB.

To understand this problem, we are interchanging second column of two matrix. MATLAB program with brief explanation for this problem has been shown in figure-1.

Figure.1 - MATLAB Program for to interchange row/column of two matrix.

This matlab program consists of 11 lines of code, which is being discuss below in details:

Line-04 : Load 3×3 matrix in A.
Line-05 : Load 3×3 matrix in B.
Line-06 : Display message written in single quote.
Line-07 : Display matrix A before column interchange operation.
Line-08 : Display matrix B before column interchange operation.
Line-09 : Copy second column of matrix A into temporary variable. Here colon (:) is used to select all elements of row which lies in column second.
Line-10 : Replace second column of matrix A by second column of matrix B.
Line-11 : Replace second column of matrix B by column stored in temporary variable.
Line-12 : Display message written in single quote.
Line-13 : Display matrix A after column interchange operation.
Line-14 : Display matrix B after column interchange operation.

To run above matlab program call it on command window by its name i.e. 'mod0110'. The screen capture of command window after recalling matlab program is shown in figure -2.

Figure.2 - Program response on Command window for interchange of row/column of two matrix.

The Response of matlab program on command window clearly shows that the second column of two matrix has been interchanged successfully.

Figure.3 - Response of help command on command window.

If user wants to know information about matlab program then he can type a command i.e. 'help program_name' on command window. A example of this has been shown in figure - 3. After execution of help command on command window it displays, whatever you written above matlab program and after '%%' in M-file.

Video Tutorial : How To Interchange a Row and a Column of a Matrix in MATLAB

Brought to you by INFO4EEE

No comments

Powered by Blogger.