Menu

where is mxArray2string function?

2007-08-25
2012-09-15
  • Bogdan Cristea

    Bogdan Cristea - 2007-08-25

    Is there any reason why mxArray2string and string2mxArray are not implemented in IT++ interface for Matlab?

     
    • Adam Piątyszek

      Adam Piątyszek - 2007-08-26

      Hi,

      No, there are no particular reasons. Probably anyone has ever needed this feature. But of course patches are always appreciated (against the SVN trunk version preferably).

      BR,
      /ediap

       
    • Bogdan Cristea

      Bogdan Cristea - 2007-08-29

      Patch for adding two conversion functions between Matlab and IT++: string2mxArray and mxArray2string

      Index: itpp/itmex.h

      --- itpp/itmex.h (revision 1160)
      +++ itpp/itmex.h (working copy)
      @@ -99,7 +99,8 @@
      double mxArray2double(const mxArray in);
      //! Convert the matlab-format mxArray to complex<double>
      std::complex<double> mxArray2double_complex(const mxArray
      in);
      - //string mxArray2string(const mxArray in);
      + //! Convert the matlab-format mxArray to string
      + std::string mxArray2string(const mxArray
      in);

      //! Convert the matlab-format mxArray to bvec
      bvec mxArray2bvec(const mxArray in);
      @@ -137,7 +138,8 @@
      void double2mxArray(const double &in, mxArray
      out);
      //! Convert complex<double> to the matlab-format mxArray
      void double_complex2mxArray(const std::complex<double> &in, mxArray out);
      - //void string2mxArray(const string &in, mxArray
      out);
      + //! Convert string to the matlab-format mxArray (there is no need to initialize the output mxArray outside this function)
      + void string2mxArray(const std::string &in, mxArray* &out);

      //! Convert bvec to the matlab-format mxArray
      void bvec2mxArray(const bvec &in, mxArray *out);
      @@ -274,6 +276,14 @@
      }

      }
      +
      + std::string mxArray2string(const mxArray *in)
      + {
      + if (in==0) mexErrMsgTxt("mxArray2string: Pointer to data is NULL");
      + std::string str = mxArrayToString(in);
      + if(str.data()==0) mexErrMsgTxt("mxArray2string: Could not convert input to string.");
      + return str;
      + }

      bvec mxArray2bvec(const mxArray in)
      {
      @@ -520,6 +530,13 @@
      tempR= (double) in.real();
      tempI= (double) in.imag();
      }
      +
      +void string2mxArray(const std::string &in, mxArray
      &out)
      +{
      + if(in.data()==0) mexErrMsgTxt("string2mxArray: Pointer to string is NULL");
      + out = mxCreateString(in.data());
      + if(out==0) mexErrMsgTxt("string2mxArray: Could not convert string to output");
      +}

      void bvec2mxArray(const bvec &in, mxArray *out)
      {

       
      • Adam Piątyszek

        Adam Piątyszek - 2007-08-29

        Thanks, but the patch is broken by reformatted text (in both Forum and email). Could you please resend it once again at my email address? In future, you can open new ticket in the Feature Request and attach the patch file there.

        Thanks!
        /Adam

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.