pass string as function argument from C to Matlab

73 Views Asked by At

I am trying to pass a string as a function argument from c to matlab. In matlab, it searches for a data file with the string name and load the data into a matrix.

function bus = new(casefile)
{
   A=loadcase(casefile);
%does additional work on that data aand returns a complex double matrix
}

I created the dll for this function using matlab compiler. This is my test code to pass a file name from C to matlab.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "matrix.h"
#include "new.h"


int run_main(int argc, const char** argv)
{
    mxArray* casename;
    mxArray* sbus=NULL;

    sbus = mxCreateDoubleMatrix(9, 1, mxCOMPLEX);
    casename = mxCreateString("case9.m");

    if (!newInitialize()) 
    {
        fprintf(stderr, "Could not initialize the library.\n");
        return -2;
    }
    else
    {
        /* Call the library function */

        mlfnew(1, &sbus, casename);
        newTerminate();


        mxDestroyArray(casename);
       
    }
    mclTerminateApplication();
    return 0;
}



int main(int argc, const char** argv)
{
    
    if (!mclInitializeApplication(NULL, 0))
    {
        fprintf(stderr, "Could not initialize the application.\n");
        return -1;
    }
    return mclRunMain((mclMainFcnType)run_main, argc, argv);
}

It shows this error "loadcase: specified M file does not exist" or "loadcase: specified case not in MATLAB's search path". I tried including the path directory with the file name string. Still shows the same error. The data file and the matlab function is in the same directory. The directory is already included in maatlab path.How to solve this issue?

0

There are 0 best solutions below