Get variables from my Matlab workspace

4 Ansichten (letzte 30 Tage)
Moataz Aly
Moataz Aly am 28 Okt. 2019
Kommentiert: Ajith Thomas am 4 Nov. 2019
I am using C mex S-function to Generate a Simulink Block called sFct_Dyn_Block by the following mex file:
mex -D__SIM_MODE__ src_Dyn_Block\sFct_Dyn_Block.c src_Dyn_Block\Dyn_Block.c src_Dyn_Block\hyd_dyn.c src_Dyn_Block\hst.c
The sequence of my code:
  1. I run a matlab file called input_users.m to collect some user inputs
  2. the user inputs are now in matlab workspace
  3. when I run my mex class I need to pass these variables some how from matlab workspace to my hyd_dyn.c class
  4. finally when I run my simulink model the output of sFct_Dyn_Block should change every time according to the userinputs
I can't pass the userinput variables from matlab workspace to my hyd_dyn.c class, I tried everything for 4 days but nothing workout.
I appreciate any help !!
  3 Kommentare
Ajith Thomas
Ajith Thomas am 4 Nov. 2019
Thanks for your valuable feedback. Its working!!!!!!

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Thomas Satterly
Thomas Satterly am 28 Okt. 2019
You should be using either inports or parameters to pass data from Matlab to you Simulink block. The "From Workspace" block works easily enough (you can just type in the name of your workspace variable). S-function parameters can be set in the Block Parameters window of the S-function block (double click on the block) and require a little more C code to set up properly, but is still easy enough. Does your S-function currently use any inputs?
  3 Kommentare
Thomas Satterly
Thomas Satterly am 28 Okt. 2019
I think you want to reference the workspace "caller" instead of base, as I beleive the "base" workspace references the Simulink model workspace, wheras the caller would be the Matlab command line
Moataz Aly
Moataz Aly am 29 Okt. 2019
Bearbeitet: Moataz Aly am 29 Okt. 2019
It should be something like this !
const mxArray *array_ptr;
double *hyd_kannal_daten;
array_ptr = mexGetVariable("base", "hyd_kannal_daten");
if (array_ptr == NULL){
mexPrintf("Could not get the variable named hyd_kannal_daten from matlab Workspace.\n");}
hyd_kannal_daten = mxGetPr(array_ptr);
The function returns a pointer to the first mxDouble element of the real part of the data.
mexPrintf("Value of user choice [hyd_kannal_daten]=%f\n", hyd_kannal_daten[0]);
I think this should be the logic required, Thanks for your help !!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Write C Functions Callable from MATLAB (MEX Files) finden Sie in Help Center und File Exchange

Produkte


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by