From: "Nikolai Yu. Zolotykh" <zny@uic.nnov.ru>
Path: news.mathworks.com!newsfeed-00.mathworks.com!webcrossing
Newsgroups: comp.soft-sys.matlab
Subject: mexCallMATLAB is slow
Message-ID: <ef45ef9.-1@webcrossing.raydaftYaTP>
Date: Tue, 14 Nov 2006 08:30:46 -0500
Lines: 46
NNTP-Posting-Host: 82.208.120.140
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
Xref: news.mathworks.com comp.soft-sys.matlab:378667



mexCallMATLAB is slower.

Let
A=zeros(1000);

I want to do an assignment

A(1,1) = 1

In MATLAB environment it requires 0.000027 seconds:

tic;A(1,1)=1;toc;
Elapsed time is 0.000027 seconds.

The following mexFucntion does the same:

/* myassignment.c */
#include "mex.h"
void mexFunction(int nOut, mxArray *pOut[],
		 int nIn, const mxArray *pIn[])
{
  mexCallMATLAB(1, pOut, 3, pIn, "subsasgn");
}

mex myassignment.c
A=zeros(1000);
S.type = '()';
S.subs = {1,1};
A=myassignment(A, S, 1);
A(1,1)

ans =

     1

But now the time requiered is 0.020915 seconds:

tic;A=myassignment(A, S, 1);toc;
Elapsed time is 0.020915 seconds.

It is too slow!

I suppose in mexCallMATLAB MATLAB copies matrices and does not make
the subscript assignment in-place!

Any suggestions are welcome.