We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Matrix Multiplication using arrays
Page Index Toggle Pages: 1
Matrix Multiplication using arrays (Read 476 times)
Matrix Multiplication using arrays
Mar 30th, 2008, 8:17am
 

i need help with simple matrix multiplication code in Processing
am using this code.

int[][] matrixA = {{3,2,-1},{0,4,6}};
int[][] matrixB= {{1,0},{5,3},{6,4}};
int[][] matrixC;


void setup()
{

 
  for(int i=0; i<2; i++){
 for(int j=0; j<2; j++){
     for(int k=0; k<3; k++){
     
     
  matrixC[i][j]= matrixC[i][j]+ matrixA[i][k] * matrixB[k][j];
   
     }
 }
  }
}

 
it gives me the error

java.lang.NullPointerException at temporary_8356_2317.setup(Temporary_8356_2317.java:32)
at processing.core.PApplet.handleDisplay(PApplet.java:1390)
at processing.core.PGraphics.requestDisplay(PGraphics.java:690)
at processing.core.PApplet.run(PApplet.java:1562)
at java.lang.Thread.run(Unknown Source)
pleas help
Re: Matrix Multiplication using arrays
Reply #1 - Mar 30th, 2008, 12:38pm
 
MatrixC needs to be initialised to a specific size before you can use it.

int [][] matrixC = new int[2][2];

And would you mind not double posting please?
Page Index Toggle Pages: 1