Plot x-axis and y-axis with mexCallmatlab

조회 수: 2 (최근 30일)
Alex
Alex 2013년 8월 24일
Hello,
In my S-function written in C I use the function mexCallmatlab to plot the content of an array and it works as I want:
real_T Gain[205];
// Some code to fill the array Gain
// convert array to mxArray
mxArray* x_ptr_gain; // Pointer
x_ptr_gain = mxCreateDoubleMatrix(1, 205, mxREAL);
memcpy(mxGetPr(x_ptr_gain), Gain, sizeof(double)*205);
mexCallMATLAB(0,NULL,1,&x_ptr_gain,"plot");
Matlab plots on the y-axis the content of my array and on the x-axis the vector number 1,2…205.
Now I would like to have on the x-axis the content of an other vector freq, which has of course the same size than Gain:
real_T freq[205];
What do I have to change to get want I want? I tried a few things, but as I am not very sure how all these structures work, I may have done mistakes and giving me the solution would be really nice :)
Thanks.

채택된 답변

Kaustubha Govind
Kaustubha Govind 2013년 8월 26일
You need to use the plot(x,y) form of PLOT:
// Copy freq into an mxArray x_ptr_freq
mxArray* x_ptr_freq = mxCreateDoubleMatrix(1, 205, mxREAL);
memcpy(mxGetPr(x_ptr_freq), freq, sizeof(double)*205);
...
mxArray *prhs[2] = {x_ptr_freq, x_ptr_gain};
mexCallMATLAB(0,NULL,2,prhs,"plot");
...
// Cleanup
mxDestroyArray(x_ptr_freq);
mxDestroyArray(x_ptr_gain);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Write C Functions Callable from MATLAB (MEX Files)에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by