Change all matrix elements from x to 1/x

Hello, i am trying to change all the elements in a single line matrix from Xj to 1/Xj. Thanks

 Accepted Answer

X=1./X;
Use a dot for element-wise division and multiplication.

3 Comments

Hey, thanks for taking the time to answer. I see now i did not word the question correctly; I meant in a single line of a matrix,not a matrix with just one line :)

Sign in to comment.

More Answers (1)

A=rand(n);
A(:,n)=1./A(:,n);

1 Comment

This would change a single column, rather than a single line (row). It happens to change the last column, by the way.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!