Path: news.mathworks.com!not-for-mail
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$1@newscl01ah.mathworks.com>
References: <kbt4p3$n00$1@newscl01ah.mathworks.com> <kbu49s$3g8$1@newscl01ah.mathworks.com> <kbv5ko$it4$1@newscl01ah.mathworks.com> <kc27ra$sau$1@newscl01ah.mathworks.com> <kc2cor$he8$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-05-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1357169589 29028 172.30.248.37 (2 Jan 2013 23:33:09 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 2 Jan 2013 23:33:09 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 756104
Xref: news.mathworks.com comp.soft-sys.matlab:785813

"Yi " <dora.zhuyi@gmail.com> wrote in message <kc2cor$he8$1@newscl01ah.mathworks.com>...
>     :
>     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