Search code examples
simulinks-function

creating .txt file from S function


I have an C mex S function which can print output to the .txt file. This code inside mdlStart(SimStruct *S) creates datafile.txt file and appends the output.

  void** pwork = ssGetPWork(S);
  FILE *datafile;

  datafile = fopen("datafile.txt","a");
  pwork[0] =  datafile;

So now I want to dynamically get the filename of .txt file from user through S function mask . so , How can I receive string value of filename from mask inside S function.


Solution

  • First, yo will need to declare the mask parameter

    enter image description here

    the, you will need to pass the filename to SFunction parameter

    enter image description here

    Last, you will use the parameter inside the sfunction, like this:

     mxGetPr(ssGetSFcnParam(S,0));
    

    See:

    http://www.mathworks.com/help/simulink/sfg/ssgetsfcnparam.html http://www.mathworks.com/matlabcentral/answers/36028-integer-parameters-to-c-mex-s-function