f



Create (Matlab) object inside C/C++ and pass it to Matlab

I'm trying to create an object inside C++ and then pass it to Matlab via en=
gPutVariable.


It seems I can create a struct

// Create a float array
mxArray *acq_data =3D mxCreateNumericMatrix(0, 0, mxSINGLE_CLASS);
float *data =3D (float *)mxCalloc(M*N, sizeof(float));
mxSetData(acq_data, data);
mxSetM(acq_data, M);
mxSetN(acq_data, N);

// Convert to struct
const char *fieldname =3D "data";
mxArray *acq_struct =3D mxCreateStructMatrix(1,1,1, &fieldname);
mxSetField(acq_struct,i,"data",acq_data);

// Convert to class ?? Does it work?
if (j=3D=3D1)
{
    const char *classname =3D "myClassTest";
    mxSetClassName(acq_struct, classname);
}
printf("j=3D%i Class=3D%s\n",j,mxGetClassName(acq_struct));

// Send to Matlab
engPutVariable(ep, "T", acq_struct);

// Execute command in Matlab
engEvalString(ep, "disp(class(T))");


However, running this indicates that Matlab still considers it a struct.

Class=3Dstruct
j =3D 0. >> struct

Class=3DmyClassTest
j =3D 1. >> struct

I have a file called myClassTest.m in the directory but it seems to be irre=
levant.

classdef myClassTest
    properties
        data;
    end
    methods
        function obj =3D myClassTest(obj)
            disp(num2str(mean(data)))
        end
    end
end


I was kind of hoping that the appearance of the object in Matlab would exec=
ute the constructor. The purpose would be to avoid engEvalString calls sinc=
e they have a high overhead - about 5ms per call regardless of the work don=
e. Not a lot but my application is calling it every 1-2ms so it's the bottl=
eneck.
0
2460acc
7/22/2015 9:20:58 AM
comp.soft-sys.matlab 211265 articles. 25 followers. lunamoonmoon (257) is leader. Post Follow

0 Replies
1227 Views

Similar Articles

[PageSpeed] 5

Reply:

Similar Artilces:

C/C++ in matlab and matlab in C/C++ ?
Is it possible to read C/C++ code in matlab and the other way around too? Hi, as long as C or C++ are written in text files you can edit them in the matlab editor. To see the special character of C or C++ coding language, in the editor go to menus: file>preferences>Edito/Debugger>language and on popup "Language" select "C/C++". This does not allow you to run the C/C++ code, just to view it i nicer way... regards, chris saneman <asdfsdf@asd.com> wrote in message <frl846 $f8i$2@news.net.uni-c.dk>... > Is it possible to read C/C...

methods to call matlab in C C++ and call C C++ in matlab
Hi, I am reading the help documents about how to program matlab and C C++ together and my questions are a little bit general. It seems that are several ways to call matlab in C C++ and another several ways to call C C++ in matlab. Please correct me if I am wrong or missing something when I try to list them. To call matlab code in C C++, are there two methods available? The first one is Matlab engine and the second one is to use MATLAB Compiler mcc to create C or C++ shared libraries from your MATLAB code. To call C C++ in matlab, are there also two methods? The first one is to call funct...

EngSim: All Matlab features and functions. 2 to 20 Times Faster than MATLAB. Use the same programming syntax as MATLAB, ANSI C/C++, /C++. Good Graphics.
ENGSIM is an Engineering Simulation & Graphics Library for Microsoft Visual C++. It has all Matlab features and functions. 2 to 20 Times Faster than MATLAB. Very Easy to program. Use the same programming syntax as MATLAB, ANSI C/C++. Graphics Support is Very Good. Support Negative Indexing for Array/Matrix, Complex Array and Complex Matrix. Support Fix-point/Floating-point Communications Engineering and Signal Processing Simulation. Support Statistical Analysis. Support User- Defined Classes. Support User-Graphics Development ...

matlab beginner: calling matlab from C/C++
I'm relatively new to the world of Matlab. I want to call my matlab own code from a C/C++ program on a machine with matlab installed. Do I need to compile the matlab code using matlab compiler tool or the matlab engine is enough for this? Thanks a lot for your help On Nov 28, 10:03 am, "Paeo Campigotto" <campigo...@dit.unitn.it> wrote: > I'm relatively new to the world of Matlab. > I want to call my matlab own code from a C/C++ program on a > machine with matlab installed. > Do I need to compile the matlab code using matlab compiler > tool or the matla...

vectorized computation in C++ such as those in Matlab (Matlab to C++)?
Dear all, Can C++/STL/Boost do the vectorized calculation as those in Matlab? For example, in the following code, what I really want to do is to send in a vector of u's. All other parameters such as t, l1, l2, l3, etc. are scalars... But u is a vector. Thus, t6 becomes a vector. t9 is an element-wise multiplication... The following code was actually converted from Matlab. If vectorized computation is not facilitated, then I have to call this function millions of times. But if vectorized computation is okay, then I can send in just a u vector with batch elements a time. I have man...

C/C++ in MATALB or MATLAB in C/C++?
Hi I've been asking on the net how to use MEX properly so that I can use C/C++ in MATLAB, but information is not forthcoming. There seems to be a lot on using MATLAB in C/C++ but not the other way around. I understand Mathworks is trying very hard to sell the Matlab Compiler, but even so, why is it SO hard to get information about MEX? Or is it that I've missed something very fundamental, meaning that I'm struggling over something that is actually quite easy? Any thoughts and info would be great. Thanks BullDog BullDog wrote: > Hi > > I've been asking on the net ...

Conversion from MATLAB to C/C++ using MATLAB compiler
I am working on conversion of .m files to c/c++. I am using the MATLAB compiler version 3.0 and MATLAB version 6.5.1. There seem to be a few functions which do not seem to get converted. The error i got while using functions like TRAIN, NETWORK and INIT (all neural-networks related functions used in the general neural network programs, newpnn.m etc) is The MATLAB compiler does not currently support MATLAB object oriented programming and the functions TRAIN , NETWORK and INIT would produce a run-time error. Could anyone please tell me as to how i can circumnavigate this problem or solve this...

matlab beginner: calling matlab from C/C++ #2
I'm relatively new to the world of Matlab. I want to call my matlab own code from a C/C++ program on a machine with matlab installed. Do I need to compile the matlab code using matlab compiler tool or the matlab engine is enough for this? Thanks a lot for your help ...

matlab beginner: calling matlab from C/C++ #3
I'm relatively new to the world of Matlab. I want to call my matlab own code from a C/C++ program on a machine with matlab installed. Do I need to compile the matlab code using matlab compiler tool or the matlab engine is enough for this? Thanks a lot for your help ...

Possible to execute a Objective C or C/C++ Code through MATLAB?
I have a Objective C Code which performs a certain function. I would like to run the code through MATLAB. If Objective C is not compatible with MATLAB and C or C++ is, then the code could be converted to C/C++. I am not a C/C++ person, so please do let me know if MATLAB is capable to handling this. Thanks, Nevine If you can call if from regular C code you can use a mex file. http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/f29502.html Stuart "Nevine Jacob" <nevinejacob1981@hotmail.com> wrote in message news:ef17b4e.-1@webx.raydaftYaTP... >I have a O...

How to pass C pointers when interfacing Matlab MCR from C/C++
We have a signal processing application for doing frequency analysis of acoustic signals. The original signal is captured in a C struct: -------------------------------------------- typedef struct _sig { unsigned long length; float *data; } Sig; -------------------------------------------- Typical length is 10M, so the size of the data is 10M*sizeof(float)=40M. We want to apply FIR filter on this signal using Matlab MCR. I have built a Matlab DLL using the deploytool from the Compiler toolbox. In the Matlab DLL there is Filt.m that includes somethin...

Calling Matlab in C in Matlab
Hi everybody! My problem can be described as follows. I have a tool in Matlab that requires calling an optimisation algorithm in C. This algorithm consists of several C-files, one of which contains the function to be minimised (CFUNCTION), and another is the main algorithm file (CMAIN). Now what I want to do is to call Matlab from CFUNCTION or CMAIN and specify my custom function (MFUNCTION) to be minimised. So, I'm calling Matlab from C from Matlab. I'm a newbie in C and MEX files. Should I rewrite CMAIN as a MEX file and include CFUNCTION in this and then use mxCallMATLAB? Or can...

C, C++, C# and MATLAB Expert
Hello all, Hope you are good. I am a expert in C and MATLAB, Feel free to contact me with your queries: onlinerapidhelp@gmail.com and join the group: https://groups.google.com/forum/#!forum/onlinerapidhelp Special Discount to first 50 Clients. I am waiting to see you, Client satisfaction is my first priority and I'll never let you down. Regards Engineer MAK ...

C/C++ and MatLab
I am trying to call and debug matlab code via C/C++. i am able to run the engdemo.c program but I cannot stop the debugger in a test MatLab file to see if this can be done. I would like the C/C++ program to spawn the MatLab environment so that I may have access to all the MatLab debugging tools but be able to read any inputs from the C/C++ calling function and return any modifications to those values back to the C/C++ function as well. I am running MatLab 6.5.1.199709 v 13. Does MatLab 7 have any added capability that I would need to do this? Reginald Robertson wrote: > > > I am tr...

Web resources about - Create (Matlab) object inside C/C++ and pass it to Matlab - comp.soft-sys.matlab

iRobot Create - Wikipedia, the free encyclopedia
iRobot Create is a hobbyist robot manufactured by iRobot that is based on the Roomba platform and was introduced in 2007. However, iRobot Create ...

The Knot Creates Facebook Page To Help Hurricane Sandy Victims Salvage Their Weddings
The damage in the wake of Hurricane Sandy included some 2,300 weddings that had to be postponed or rescheduled, according to wedding portal The ...

Swedish man creates giant snow penis to say sorry for destroying smaller snow penis
Emilian Sava used a snow blower to create the 70 metre long drawing, after people online objected to him brushing away a much smaller drawing ...

Another Lawmaker Is Trying To Create A Photography-Free Zone For Police Officers
"Say cheese!" is not a phrase that bacon wants to hear.

Create your own mashup videos with ease, just use KnowMe
... 8 or later, and is designed for iPhone, iPad, and iPod touch. Its a free download on the App Store, without any ads or in-app purchases. Create ...

Create the Perfect Email Signature With This Cheat Sheet
... – yet. How does your email signature look? Here is a great infographic that will guide you in creating the perfect email signature. Create ...

"Saudi Arabia’s top cleric has declared the playing of chess 'forbidden'... a waste of time and money ...
Grand Mufti Sheikh Abdulaziz Al-Sheikh called it “the work of Satan.” “It makes the rich man poor, and makes the poor man rich,” he said. “It ...

Here's why cold and snow create major problems at airports
Snow, ice, and freezing equipment and workers all slow down the process of getting planes into the air and onto the ground.

Apple says it has helped create over a million European jobs
... on job creation come as European tax authorities continue to consider how much tax the company owes in the region. Apple claims to have created ...

Google creates fix for zero-day kernel flaw, says effect on Android is greatly exaggerated
Google has developed a patch for a recently reported vulnerability in the Linux kernel and shared it with Android manufacturers.

Resources last updated: 1/25/2016 10:38:50 AM