WICHTIG: Der Betrieb von goMatlab.de wird privat finanziert fortgesetzt. - Mehr Infos...

Mein MATLAB Forum - goMatlab.de

Mein MATLAB Forum

 
Gast > Registrieren       Autologin?   

Partner:




Forum
      Option
[Erweitert]
  • Diese Seite per Mail weiterempfehlen
     


Gehe zu:  
Neues Thema eröffnen Neue Antwort erstellen

mxCreateNumericArray und mexPutVariable

 

Janus
Forum-Newbie

Forum-Newbie


Beiträge: 1
Anmeldedatum: 15.04.11
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 15.04.2011, 15:46     Titel: mxCreateNumericArray und mexPutVariable
  Antworten mit Zitat      
Hallo alle,

ich versuche aus meiner S-Function einen Vektor bestehend aus vier Signalen in den Matlab Workspace zu exportieren. Leider scheine ich irgend einen Buffer Overrun zu bekommen, kann aber leider nicht herausfinden wo und warum.

Das Problem tritt zudem offenbar nur auf sofern ich ein Numeric Array vom Typ 32bit uint erzeuge, 16bit uint funktioniert (zumindest scheinbar)

Code:

static void mdlOutputs(SimStruct *S, int_T tid)
{
  const uint16_T * IN_PORT_0_NAME = ssGetInputPortSignal(S,0);
  const uint16_T * IN_PORT_1_NAME = ssGetInputPortSignal(S,1);
  const uint16_T * IN_PORT_2_NAME = ssGetInputPortSignal(S,2);
  const uint32_T * IN_PORT_3_NAME = ssGetInputPortSignal(S,3);

  // Write Simulation Output to Workspace, Param1 = variable name
  if (ssGetNumSFcnParams(S) == 1)
  {
    // Create Numeric Array for export to Workspace
    mwSize dims[] = {1, 4};
    mxArray * mxptr = mxCreateNumericArray(2, dims, mxUINT32_CLASS, mxREAL);
    if(mxptr != NULL)
    {
      // Get Variable Name from submitted Parameter
      char_T * varname = mxArrayToString(ssGetSFcnParam(S, 0));
      if(varname != NULL)
      {
        // Get Pointer to Data Array
        uint32_T * data = mxGetData(mxptr);
        if(data != NULL)
        {
          data[0] = (uint32_T)*IN_PORT_0_NAME;
          data[1] = (uint32_T)*IN_PORT_1_NAME;
          data[2] = (uint32_T)*IN_PORT_2_NAME;
          data[3] = *IN_PORT_3_NAME;                % <-- hier kommt zumindest teilweise müll raus
        }
        mexPutVariable("base", varname, mxptr);
        mxFree(varname);
      }
      mxFree(mxptr);
    }
  }
}
 


Jemand ne Idee?

Viele Dank im voraus Wink
Private Nachricht senden Benutzer-Profile anzeigen


Neues Thema eröffnen Neue Antwort erstellen



Einstellungen und Berechtigungen
Beiträge der letzten Zeit anzeigen:

Du kannst Beiträge in dieses Forum schreiben.
Du kannst auf Beiträge in diesem Forum antworten.
Du kannst deine Beiträge in diesem Forum nicht bearbeiten.
Du kannst deine Beiträge in diesem Forum nicht löschen.
Du kannst an Umfragen in diesem Forum nicht mitmachen.
Du kannst Dateien in diesem Forum posten
Du kannst Dateien in diesem Forum herunterladen
.





 Impressum  | Nutzungsbedingungen  | Datenschutz | FAQ | goMatlab RSS Button RSS

Hosted by:


Copyright © 2007 - 2025 goMatlab.de | Dies ist keine offizielle Website der Firma The Mathworks

MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.