Transpose in Matlab
I Have the Following Code Shown Below. I Don’t Get Why You Need to Transpose the Matrix. Could Someone Explain Why a Transpose Is Needed Here? Code: Function B...
I have the following code shown below.
I don’t get why you need to transpose the matrix.
Could someone explain why a transpose is needed here ?
Code:
function b = back_and_forth(n)
b = reshape([1:1:n^2],[n,n])’
b([2:2:n], : ) = b([2:2:n],[end:-1:1])
end
1 Answer
Transposing and Complex Transposing Conventions
It is due to how reshape() shapes the vector. In this case reshape() reshapes the 1-by-16 vector into a 4-by-4 array by traversing column-wise. In this case, you must take the transpose .' or ' complex-conjugate transpose to make each column effectively be a row, similar to rotating the matrix. Visually:
Must Read
Test Script:
n = 4;
b = reshape([1:1:n^2],[n,n]);
b
b'
b = b';
b([2:2:n],:) = b([2:2:n],[end:-1:1]);