<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with #transpose - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=%23transpose</link>
      <pubDate>Sun, 08 Aug 2021 20:19:26 +0000</pubDate>
         <description>Tagged with #transpose - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/tagged%23transpose/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>Problems with transpose a 2D array or matrix ...</title>
      <link>https://forum.processing.org/two/discussion/25921/problems-with-transpose-a-2d-array-or-matrix</link>
      <pubDate>Fri, 12 Jan 2018 09:39:11 +0000</pubDate>
      <dc:creator>nowtronix</dc:creator>
      <guid isPermaLink="false">25921@/two/discussions</guid>
      <description><![CDATA[<p>Hello !</p>

<p>I have a question about the transpose of a 2D Array or Matrix. 
I wrote a short programm to explain my problem:</p>

<pre><code>int [][] matrix = { {0, 0, 0}, 
                    {0, 1, 0}, 
                    {1, 1, 1} };

int [][] tmpMatrix = new int [3][3];
int [][] newMatrix = new int [3][3];

void setup() {
  size(800, 600);
  background(0);
  tmpMatrix = matrix;
}

void draw() {
  drawMatrix(newMatrix);
  for (int j = 0; j&lt;3; j++) {
    for (int i = 0; i&lt;3; i++) {

      **newMatrix[j][i]**=tmpMatrix[i][j];
    }

    print("\n");
  }
  drawMatrix(matrix);
  drawMatrix(tmpMatrix);
  drawMatrix(newMatrix);
  noLoop();
}

void drawMatrix(int [][] matrix) { 
  for (int j = 0; j&lt;3; j++) {
    print("\n");
    for (int i = 0; i&lt;3; i++) {
      print(matrix[j][i]);
    }
  }
  print("\n");
}
</code></pre>

<p>So this programm works fine and I get the transpose of the Matrix in "newMatrix".</p>

<p>But when I change the variable from "newMatrix" into "matrix" (I mean inside of the two for loops) the transposed matrix is wrong !</p>

<p>I don't understand what is the problem here.</p>

<p>Thank you a lot !</p>
]]></description>
   </item>
   </channel>
</rss>