How can I pass structures to a mex-file?

Hello everyone,
I am trying to compile a C code in MATLAB, I have been reading through a bunch of tutorial and questions about this topic in the last 4 days and I did not understand it at all yet.
Let me explain my problem, I have this structure here.
typedef struct _BoardDef
{
U32 RecordCount;
U32 RecLength;
U32 PreDepth;
U32 ClockSource;
U32 ClockEdge;
U32 SampleRate;
U32 CouplingChanA;
U32 InputRangeChanA;
U32 InputImpedChanA;
U32 CouplingChanB;
U32 InputRangeChanB;
U32 InputImpedChanB;
U32 TriEngOperation;
U32 TriggerEngine1;
U32 TrigEngSource1;
U32 TrigEngSlope1;
U32 TrigEngLevel1;
U32 TriggerEngine2;
U32 TrigEngSource2;
U32 TrigEngSlope2;
U32 TrigEngLevel2;
}BoardDef, *pBoardDef;
Where U32 is defined as below
typedef unsigned long U32
I want to create the mex file to the the function used below
status = AlazarSetRecordCount( h, bd.RecordCount);
Where bd is defines as below
BoardDef bd;
The problem is, I don`t know how to handle the structure thing in the mex file, I have read through the example phonebook.c example but it did not clarify me that much.
I doing as follow:
#include "mex.h"
#include <AlazarApi.h>
#include <AlazarError.h>
#include <AlazarCmd.h>
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[] )
{
double *x0,*y0,*y1;
RETURN_CODE status;
U32 RecordCount;
int handle;
mwSize mrows,ncols;
mxArray *rc; //RecordCount
/* Create matrix for the return argument. */
plhs[0] = mxCreateDoubleMatrix(1,1, mxREAL);
plhs[1] = mxCreateDoubleMatrix(1,1, mxREAL);
/* Assign pointers to each input and output. */
x0 = mxGetPr(prhs[0]);
y0 = mxGetPr(plhs[0]);
y1 = mxGetPr(plhs[1]);
/* Call the timestwo subroutine. */
handle = (int)x0[0];
status = AlazarSetRecordCount( handle, RecordCount);
*y0 = status;
*y1 = *rc;
}
I know that I have some mistakes in that code, for example in the last line I am assigning rc to y1 but I have nothing in rc yet because I don`t know where I have to create the structure in the mexfile, but I know that to access a filed of the structure I use mxGetField.
So my question is, where do I declare my whole structure and how do I pass it as a parameter of the function AlazarSetRecordCount?
All help is welcome guyz. Thank you.

3 Commenti

Are you trying to pass a MATLAB structure into a mex routine, then convert it to the C struct you show above, then pass that along to a C function, then return something back to MATLAB?
I don't know if that's what Kaio was trying to do, but that's what I'm trying to do -- can you explain how to do it?
@Abigail: Sorry, what are you trying to do? Is this a new question? Then please open a new thread.

Accedi per commentare.

Risposte (1)

Kaio
Kaio il 7 Giu 2013
No one knows anything about it? ANY help is welcome, really any help.

Categorie

Richiesto:

il 6 Giu 2013

Commentato:

Jan
il 31 Ago 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by