# Question:Problem with codegen applied to a rectangular (Array) matrix.

## Question:Problem with codegen applied to a rectangular (Array) matrix.

Maple 2017

Hey,

I am using codegen to generate code from Maple expressions. More specifically I want to export non quadratic matix. The export works for matrices that have more columns than rows, but not for matrices with more rows than columns. There I receive the error:

Error, (in codegen/array/entry) 2nd index, 3, larger than upper array bound 2

A workaround would be to transpose the matrix before the export, and to transpose on the import (in Matlab) but I don't want to overcomplicate my code. Thanks for your help!

I have attached a demonstration worksheet below.

 > ## test codegen non quadratic returnarray
 > ## works #Myfun := Matrix(3,3)
 > ## works #Myfun := Matrix(2,3):Myfun(2,3):= 3*b;
 > ## does not work Myfun := Matrix(3,2):Myfun(3,2):= 3*b;
 (1)
 > Myfun(1):= 7*a;
 (2)
 > ## codegen works best with arraybased matrices, and call by reference becomes possible
 > returnArray:= convert(Myfun,matrix)
 (3)
 > codegen[makeproc](Myfun,[a,b])
 > codegen[makeproc](returnArray,[returnArray,a,b])
 > codegen[makeproc](returnArray,[a,b])
 >