MatLab-Engine can't use a Variable for the GUI?
이전 댓글 표시
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
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
2012년 8월 19일
Walter Roberson
2012년 8월 19일
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?
답변 (1개)
Walter Roberson
2012년 8월 19일
0 개 추천
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
Oliver
2012년 8월 19일
Walter Roberson
2012년 8월 19일
I do not understand what you mean by "can't handle the Matrix to build up my GUI" ??
Oliver
2012년 8월 19일
카테고리
도움말 센터 및 File Exchange에서 Call MATLAB from C++에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!