MatLab-Engine can't use a Variable for the GUI?
Mostra commenti meno recenti
I'm stuck at using my variable "ball" from C++ in the MatLab-Engine to get my GUI running.
However by typing "whos" in die MatLab-Engine console it gives me my variable.
In Short: I create a 2D-array in C++, start the MatLab Engine via C++, create an mxArray, which will be the size of the 2D-array, and pass this mxArray to MatLab to build my GUI, which isn't working. But in the command console this Matrix is available and filled.
I just give you some Code snippets in C++:
double ball[5][7];
mxArray *m_ball;
m_ball = mxCreateDoubleMatrix(7, 5, mxREAL);
memcpy((void *)mxGetPr(m_ball), (void *)ball, sizeof(double)ball);
engPutVariable (ep, "ball", "m_ball");
Now i want to use MatLab to do some maths and show me where those balls are with the GUI and here is the never ending problem in the MatLab M-File:
ball3=rectangle('Position',[100, ball(3,3), 20,20],'Curvature',[1,1],'FaceColor','r');
It always ends at drawing the ball with the position from the variable. The Debugger gives me "Index exceeds matrix dimensions."
Does the GUI work in some other way than the rest? If i try to calculate with the Matrix in the MatLabWorkspace by typing some Commands in C++, it works perfectly.
Creating a MatFile and load it each time in MatLab works too, though it isn't the way I want it to be. The same goes with declaring the variable in the MatLab code, then it works too.
Any Tips would be great.
Oliver
4 Commenti
You forgot to mention how you try to provide the variable m_ball to the Matlab workspace. Where do you define the variable "ball" in Matlab?
"sizeof(double)ball" looks strange. ball has the type double and I do not expect that the memcpy from (void *)ball creates what you expect.
Oliver
il 19 Ago 2012
Walter Roberson
il 19 Ago 2012
Please expand on "It always ends at drawing the ball with the position from the variable."
Also, when you say "The Debugger gives me "Index exceeds matrix dimensions."" then which line of code is that, and what size() is the variable and what index are you using?
Risposte (1)
Walter Roberson
il 19 Ago 2012
0 voti
I am not at all sure that I understand what you are asking.
If you have defined a variable at the C level, you cannot access the variable from the MATLAB level except by returning it from the mex routine (or perhaps by calling some routine to push the variable to the MATLAB engine.) But your code appears to be trying to use the variable itself rather than calling a routine that returns a value.
You should think of mex routines as being essentially in a different workspace than the calling routine.
3 Commenti
Oliver
il 19 Ago 2012
Walter Roberson
il 19 Ago 2012
I do not understand what you mean by "can't handle the Matrix to build up my GUI" ??
Oliver
il 19 Ago 2012
Categorie
Scopri di più su Call MATLAB from C++ in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!