Matrix add row - most efficient way

Which is the most efficient way to add a new row to an existing matrix.

My solution so far is:

rowc=mxGetsize(mymx,0);
colc=mxGetsize(mymx,1);

newmx=Matrix(rowc+1,colc,0);
for (rw=0;rw<rowc;rw++)
{
for (c=0;co<colc;c++)
{
 newmx[rw][co]=mymx[rw][co];
}

Any better solutions available ?

thx michael

This is inefficient. It is better to use MxGetBlock()/MxSetBlock() to transfer elements row-at-a-time.

1 Like