MATLAB: Creating a Matrix that is a manipulation of another matrix

matrix manipulation

Hi, I'm very new to Matlab, and I have a question about creating a matrix. If there is a matrix A = [a b ; c d], how do you create a matrix = [a -b ; c -d]? So the second column entries of A are multiplied by -1.
Thank you.

Best Answer

A(:,2)=-A(:,2); % negate elements in original
or
A(:,2)=-1*A(:,2);
or
B=[A(:,1) -A(:,2}]; % new array keeping old
Any number of additional ways are possible including, of course linear algebra methods...
B=A*[1 0;0 -1];
Related Question