An effect matrix, just as any other variable or object, can only work as long as it is not deleted or overwritten. Your matrices are fine inside your functions, but just garbage outside. When you want a variable to survive the return of the function, you must declare it global or static.