How can I pass structures to a mex-file?

12 views (last 30 days)
Kaio
Kaio on 6 Jun 2013
Commented: Jan on 31 Aug 2017
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 Comments
Abigail Cember
Abigail Cember on 31 Aug 2017
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?
Jan
Jan on 31 Aug 2017
@Abigail: Sorry, what are you trying to do? Is this a new question? Then please open a new thread.

Sign in to comment.

Answers (1)

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

Categories

Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!