×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Matrix declaration in c-file for creating dll

Matrix declaration in c-file for creating dll

Matrix declaration in c-file for creating dll

(OP)
I want to make a dll for a VB program. The c-code below shows wrapper file with variables a and b. What code I have to build if I use matrixes instead of doubles?!?


#include "eigenwaardelib.h"
#include "matlab.h"

double __stdcall eigenwaardewrap(double a, double b)
{
    mxArray *a_ptr;
    mxArray *b_ptr;
    mxArray *y_ptr;
    double *y;
    double ret;

    /* Create an mxArray to input into mlfeigenwaarde */
    a_ptr = mlfScalar(a);
    b_ptr = mlfScalar(b);

    eigenwaardelibInitialize();
    y_ptr = mlfEigenwaarde(a_ptr, b_ptr);

    /* The return value from mlfeigenwaarde is an mxArray so we must extract the data from it */
    y = mxGetPr(y_ptr);
    ret = *y;
    /* Return a double precision number to Visual Basic */
    return(ret);
}

RE: Matrix declaration in c-file for creating dll

Do you want a_ptr & b_ptr to be matrices? Use the command:
a_ptr=mxCreateDoubleMatrix(nrows,ncols,MX_REAL);

Then you'll need to retreive a pointer to the mxArray to populate it with values (ap=mxGetPr(a_ptr)). The array is 1-D, so you can set index (2,3) to 1.1 with the command   ap[(3-1)*nrows+2]=1.1
--Remember, MATLAB is columnwise, so it goes down the 1st column in the matrix, then the next, and so on.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources