Plot from C Mex function and C types

3 次查看(过去 30 天)
Hello,
I'am writing an S-function in C and I need at some point to plot the content of DWork vectors (the first Dwork vector being the x-axis and the second the y-axis).
I tried the following:
mexCallMATLAB(0,x,1,y,"plot");
However this doesn't work because x and y are not of type mxArray but REAL T. Indeed this is how x and y are defined:
real_T *x = (real_T*) ssGetDWork(S,0);
real_T *y = (real_T*) ssGetDWork(S,1);
It is not possible to change the type of x and y. Is it possible to copy the content of x and y in a mxArray so that the function mexCallMATLAB can be used? I am not really an expert in C, so hopefully it won't be too hard to implement :o
Besides, is it possible to save the content of a Dwork vector (or a mxArray once "converted") in the Matlab workspace ?
Thanks.

采纳的回答

Kaustubha Govind
Kaustubha Govind 2013-8-19
I would recommend looking at the documentation for mxCreateDoubleMatrix, particularly the examples listed at the bottom of the page, to understand how you can copy over your data into an mxArray.
However, I'm not sure why you'd want to call the PLOT command from within the S-function. Why not just mark your DWorks as discrete states using ssSetDWorkUsedAsDState and select the Save to Workspace options on the Data Import/Export pane of the Configuration Parameters dialog box - this will log the state values to the workspace at the end of simulation, at which point you can use the block's StopFcn callback to automatically plot the data at the end of simulation.

更多回答(1 个)

Alex
Alex 2013-8-21
Thank you I've managed to copy the Dwork content into an mxArray and the it plots what I want.
Actually I'm coding an online FFT algorithm and as new data incomes I need to be able to check the evolution of the coherence function and I think calling mexPlot is the easiest way to do it. It won't be enough to plot the content of the Dwork vectors at the end of the simulation, since I won't be able to know which part of the signal had an effect on the coherence function.
  1 个评论
Kaustubha Govind
Kaustubha Govind 2013-8-21
FYI, there is also a run-time API (see Access Block Data During Simulation) that you can use to attach a listener to the block Output method that can read Discrete State data.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by