Problem converting std::vector type to mwArray

Hello,
I am newbie usign Matlab C++ libraries.I am trying to convert a vector, for example Powervector, to the mwArray type so that by matlab function can use it. The Powervector has the following format in C++, std::vector<double> Powervector . Code that I use:
mwArray Tmsa(1, TotalPower.size(), mxDOUBLE_CLASS);
Tmsa.SetData(&TotalPower[0], TotalPower.size());
I have a problem when I debbug it. Debbuger show this message:
_"An unhandled exception of type 'System.AccessViolationException' occurred in DevicePrognosis.exe
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt."_
Any idea how can I fix it?
Thank you.

Respuestas (2)

Kaustubha Govind
Kaustubha Govind el 23 de Mayo de 2012
Strange, seems like that should work. How about if you try the documentation example:
double rdata[4] = {1.0, 2.0, 3.0, 4.0};
mwArray a(2, 2, mxDOUBLE_CLASS);
a.SetData(rdata, 4);
Just want to see if the issue has something to do with STL containers or heap-allocated data.

2 comentarios

enrique nares
enrique nares el 29 de Mayo de 2012
Hello Kaustubha!
I tried with the documentation answer too. It doesn't works and the same problem occurs. Any Idea?
Thanks in advance.
Kaustubha Govind
Kaustubha Govind el 29 de Mayo de 2012
Then it looks like there is some other issue with your application. Have you initialized the MCR by calling mclInitializeApplication? There is an example in the documentation that does a similar set of commands as I suggested in my initial answer. Type "edit([matlabroot '/extern/examples/compiler/matrixdriver.cpp'])" at the MATLAB prompt to see it.

Iniciar sesión para comentar.

enrique nares
enrique nares el 30 de Mayo de 2012

0 votos

Hello,
I used the documentation example and I found the answer. I forgot mclInitializeApplication() function. Now it works but I have another problem. I have a std::vector<string> str and I want to pass it into mwArray. Any Idea how can I do that?
Thanks in advance.

1 comentario

Kaustubha Govind
Kaustubha Govind el 6 de Jun. de 2012
If you need to create a char matrix, you might be able to use this constructor: http://www.mathworks.com/help/releases/R2011b/toolbox/compiler/mwarraymwsizenum_stringsconstcharstr.html
If you need a cell-array of strings, you probably need to loop over each element and use the Get and Set methods as in the example here: http://www.mathworks.com/help/releases/R2011b/toolbox/compiler/voidsetconstmwarrayarr.html

Iniciar sesión para comentar.

Categorías

Productos

Preguntada:

el 23 de Mayo de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by