matlab - Matrix main diagonal change -
i have matrix below: a=
1 2 1 2
i transform to: b=
1 1 2 2
i have tried use output of diag(a)
, don't know how concatenate same output twice.
it looks you're swapping anti-diagonal elements. way instead of using transpose indexing:
a([2 3]) = a([3 2]);
how above code works can access elements in matrix using column-major linear indices. means traverse matrix top bottom, left right. therefore, want access second row first column index 2, first row second column index 3. have swap 2 values, left-side indices reverse of right-side indices.
Comments
Post a Comment