Filter löschen
Filter löschen

using std::vector<double> inside mexfunction()

1 Ansicht (letzte 30 Tage)
Kaushik
Kaushik am 7 Jun. 2013
hi,
i have the following
----myfunction.cpp------
#include<mex.h>
#include<math.h>
#include<matrix.h>
#include<stdio.h>
#include "mydllfunctionheader.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
mystruct XXX;
XXX.a=0;
XXX.b.resize(10,0.);
mydllfunction(XXX);
}
----mydllfunctionheader.h----
#include <vector>
#include <map>
struct mystruct
{
double a;
std::vector<double> b;
}
__declspec(dllexport) int __cdecl
mydllfunction(mystruct XXX);
----------------------
problem is inside the mexfunction i make XXX.b to be of size 10 vector. but in the debug mode when i enter the mydllfunction the vector b gets messed up. any doubles (such as variable "a") are okay but any vectors are not okay.
Can anyone please comment on what is going on.
also i cannot have extern "C" before my _declspec. becuase though in the simple example i provide above i am returning int in the actual case i will be returning an complex object.
thanks in advance

Antworten (0)

Kategorien

Mehr zu Write C Functions Callable from MATLAB (MEX Files) finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by