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; 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.
No products are associated with this question.
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.