Path: news.mathworks.com!not-for-mail
From: "Faisal " <faisal_mufti.nospam@yahoo.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Pass structure to MATLAB
Date: Sat, 3 Nov 2007 02:48:34 +0000 (UTC)
Organization: Australian National University
Lines: 57
Message-ID: <fggni2$4sk$1@fred.mathworks.com>
References: <fgb6fp$8rt$1@fred.mathworks.com> <6p9li3t0t4mc554emmf7q74rd5iut85d5l@4ax.com> <fgef3h$qrv$1@fred.mathworks.com> <70jmi39c96s8iudh4r1ajrrto95r873uak@4ax.com>
Reply-To: "Faisal " <faisal_mufti.nospam@yahoo.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1194058114 5012 172.30.248.37 (3 Nov 2007 02:48:34 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 3 Nov 2007 02:48:34 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1014052
Xref: news.mathworks.com comp.soft-sys.matlab:435895


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);
    
}