Path: news.mathworks.com!newsfeed-00.mathworks.com!newscon02.news.prodigy.net!prodigy.net!news.glorb.com!cycny01.gnilink.net!spamkiller2.gnilink.net!gnilink.net!trndny02.POSTED!702e7bde!not-for-mail
From: James Tursa <aclassyguywithaknotac@hotmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Pass structure to MATLAB
Message-ID: <gr9oi31ibje2d1608d9b53kef8a5kr8hvk@4ax.com>
References: <fgb6fp$8rt$1@fred.mathworks.com> <6p9li3t0t4mc554emmf7q74rd5iut85d5l@4ax.com> <fgef3h$qrv$1@fred.mathworks.com> <70jmi39c96s8iudh4r1ajrrto95r873uak@4ax.com> <fggni2$4sk$1@fred.mathworks.com>
X-Newsreader: Forte Agent 3.3/32.846
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Lines: 70
Date: Sat, 03 Nov 2007 07:51:31 GMT
NNTP-Posting-Host: 71.112.104.61
X-Complaints-To: abuse@verizon.net
X-Trace: trndny02 1194076291 71.112.104.61 (Sat, 03 Nov 2007 03:51:31 EDT)
NNTP-Posting-Date: Sat, 03 Nov 2007 03:51:31 EDT
Xref: news.mathworks.com comp.soft-sys.matlab:435906


On Sat, 3 Nov 2007 02:48:34 +0000 (UTC), "Faisal "
<faisal_mufti.nospam@yahoo.com> wrote:

>Hi James
>I do like to pass on arguments like [a,b]=strucmex(in1,in2);
>I have modified you mex function and I have been able to
>pass input arguments but yet to succeed with output
>arguments. Your example is no doubt an excellent reply. But
>as this is an initial block and I need to know if I have my
>somefun, how will I be able to pass argument input and
>output argumnets as shown in MEX help in matlab along with
>structure passing that you have shown. 
>
>void mexFunction(int nlhs, mxArray *plhs[], int nrhs,
>     const mxArray *prhs[])
>{
>    struct Frame *f;
>    struct UShortFrame *u;
>    size_t t1 = 1;
>    int i,mrows, ncols;;
>    double *f_count;
>    char *filename;
>    
>    mrows = mxGetM(prhs[0]);
>    ncols = mxGetN(prhs[0]);
>    f_count = mxGetPr(prhs[0]);
>    filename=mxArrayToString(prhs[1]);
>    
>
>    ifstream filein(filename, ios::in | ios::binary);   
>        
>      if(!filein) {
>          std::cout << "Cannot open file to read.\n"; }
>           
>   u = (struct UShortFrame *) mxCalloc( t1, sizeof(struct
>UShortFrame) ); 
>   f = (struct Frame *) mxCalloc( t1, sizeof(struct Frame) );
>
>   (filein.read((char*)u,sizeof(UShortFrame)));
>     
>     {
>            f->frame_no = u->frame_no;
>            for (int i = 0; i < ARRAYSIZE; ++i)
>               {
>                    f->dist[i]=u->dist[i];
>                    f->ampl[i]=u->ampl[i];
>
>               }
>   }
>    
>    if( mPut1(f, "f") )
>        mexPrintf("mPut1 for f did not work\n");
>    
>    if( mPut2(u, "u") )
>        mexPrintf("mPut2 for u did not work\n");
>    filein.close();
>    mxFree(f);
>    mxFree(u);
>    
>}

So if you want to invoke it as follows:

[a,b]=strucmex(in1,in2);

then do you want f to be put into the first output argument a, and u
to be put in the second arbument b?  I can easily modify my code to do
this if that is what you really want.

James Tursa