Plot x-axis and y-axis with mexCallmatlab

1 view (last 30 days)
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.

Accepted Answer

Kaustubha Govind
Kaustubha Govind on 26 Aug 2013
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);

More Answers (0)

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!