Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Matrix::transpose() {
- if (!arr) return;
- else {
- Matrix temp = *this; //save current matrix to the temp
- int t = n;
- n = m;
- m = t; //swap width and height
- arr = new double*[n];
- for (int i = 0; i < n; i++)
- arr[i] = new double[m]; //allocate memory for transposed matrix
- for (int i = 0; i < n; i++)
- for (int j = 0; j < m; j++)
- arr[i][j] = temp.arr[j][i]; //fill new matrix with elements from temp
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement