Plot x-axis and y-axis with mexCallmatlab

1 vue (au cours des 30 derniers jours)
Alex
Alex le 24 Août 2013
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.

Réponse acceptée

Kaustubha Govind
Kaustubha Govind le 26 Août 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);

Plus de réponses (0)

Catégories

En savoir plus sur Write C Functions Callable from MATLAB (MEX Files) dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by