Jump to content
  • Advertisement
Sign in to follow this  
johnnyBravo

Trying to work out transpose of n sized matrix

This topic is 4518 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I don't know what is wrong with me, but I can't work out how to get the transpose of a n sized matrix. I can do it fine manually, but I can't wrap my head around it. So if I had the code:
const int n = 4;
int matrix[n][n];
//initialize matrix...


can someone tell me an algorithm to transpose this matrix? Thanks

Share this post


Link to post
Share on other sites
Advertisement
Just remember that m[j] and m[j] are swapped, and diagonal elements are unchanged. There are various ways to implement the function, depending I suppose on how concerned you are with efficiency. Here's one way you could do it (no guarantee of correctness):
for (int j = 1; j < size; ++j) {
for (int i = 0; i < j; ++i) {
float temp = m[j];
m[j] = m[j];
m[j] = temp;
}
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!