From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: mexCallMATLAB crashes in loops?
Date: Wed, 2 Jan 2013 23:33:09 +0000 (UTC)
Organization: Boeing Co
Lines: 12
Message-ID: <kc2g3l$sb4$>
References: <kbt4p3$n00$> <kbu49s$3g8$> <kbv5ko$it4$> <kc27ra$sau$> <kc2cor$he8$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1357169589 29028 (2 Jan 2013 23:33:09 GMT)
NNTP-Posting-Date: Wed, 2 Jan 2013 23:33:09 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 756104
Xref: comp.soft-sys.matlab:785813

"Yi " <> wrote in message <kc2cor$he8$>...
>     :
>     for(istruct=0;istruct<ninputs;istruct++){
>         for(ifield=0; ifield<nfields; ifield++){
>             tmp=mxDuplicateArray(mxGetFieldByNumber(prhs[0],istruct,ifield));
>             mxSetFieldByNumber(incall[0], 0, ifield, tmp);
>         } 

I should further add that if you are going to be working with large variables, there are better functions to use for getting read-only copies of stuff into struct or cell elements ... they are the undocumented functions mxCreateSharedDataCopy and mxCreateReference. Their use would allow you to create a struct or cell array that contains only parts of your original struct or cell without actually copying the data (i.e., you just copy the variable pointers over to the new array in a special way using the afore-mentioned undocumented functions).

James Tursa