How to swap elements of the first column of the S matrix with the first line elements?

1 次查看(过去 30 天)
Hi I have a matrix
A=[1 2 3;
4 5 6;
7 8 9]
but I want to switch the first column with first line like this
A=[1 4 7;
2 5 6;
3 8 9].
What it's the fast way to do it? Any help is appreciated! Thank you

采纳的回答

James Tursa
James Tursa 2018-5-16
If only the 1st column and row are involved, e.g. a simple swap:
A1 = A(:,1);
A(:,1) = A(1,:);
A(1,:) = A1;

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by