Wednesday, May 6, 2015

Swap Rows and Columns of the matrix using Matlab

In the most of the algorithm swapping of the matrices are very necessary. Example in the Gauss elimination procedure in order to perform the Row operations swapping is important.

Example Program:


%% Close all files and clear screen  %%


close all;
clear all;
clc;


%% Genrate Matrix A

A=[1 2 3; 4 5 6; 7 8 9]

%% Swap the rows of the matrix

Y=A([1,3,2],:)


%% Swap the columns of the matrix

Z=A(:,[1,3,2])

No comments:

Post a Comment