I wanna replacing 2nd and 3rd column to each other. How can I write a command?
28 views (last 30 days)
More Answers (2)
Image Analyst on 9 Jan 2013
column2 = m(:,2); % Save old column2.
m(:,2) = m(:,3); % Move col3 to col2.
m(:,3) = column2; % Make col3 the old col2
Amith Kamath on 9 Jan 2013
Assuming I understand the question right, here is an example of how it could be done:
x = magic(5); % a random matrix for illustration.
l = 1:size(x,2); % get the number of columns of x.
l(2:3) = [3 2]; % setup index replacement.
y = x(:,l); % y will have the same elements as x, with rows 2 and 3 exchanged.