Thread Subject:
mxCreateString usage

Subject: mxCreateString usage

From: Alin

Date: 5 Jul, 2012 14:05:08

Message: 1 of 4

Hello everyone,

I'm trying to start a simulation from within an S-Function which is in my initial simulation.
I'm using mxCallMATLAB and the function sim.

My problem is the following:
I need to execute the sim function with a couple of parameters. I want to pass them as a string and for that I'm using mxCreateString:

const char *option = "'example.mdl',35:60";
    mxArray *prhs = mxCreateString(option);
    mexCallMATLAB(0,NULL,1,&prhs,"sim");

the error that I get is:
The file name ''example.mdl',35:60' is invalid because it does not have the extension ".mdl" or ".slx".

The problem is that when I use mxCreateString it appends ' characters at the beginning and at the end of my string.

Any idea on how so solve this?
Your help is greatly appreciated.

Alin

Subject: mxCreateString usage

From: Phil Goddard

Date: 6 Jul, 2012 04:20:07

Message: 2 of 4

 mexCallMATLAB and sim are working as expected.

You are asking mexCallMATLAB to call sim with one input that is a string.
When sim is called with one input that is a string it requires that string to be the name of a model, which in your case it is not, and hence it errors out, giving you a message that the string doesn't correspond to a model file.

What it looks like you really want it to call sim with two inputs -- the first being a string and the second being a numeric valued matrix.

Phil.

Subject: mxCreateString usage

From: Alin

Date: 9 Jul, 2012 08:50:07

Message: 3 of 4

"Alin " <alin.ionascu@live.com> wrote in message <jt46uj$jor$1@newscl01ah.mathworks.com>...
> Hello everyone,
>
> I'm trying to start a simulation from within an S-Function which is in my initial simulation.
> I'm using mxCallMATLAB and the function sim.
>
> My problem is the following:
> I need to execute the sim function with a couple of parameters. I want to pass them as a string and for that I'm using mxCreateString:
>
> const char *option = "'example.mdl',35:60";
> mxArray *prhs = mxCreateString(option);
> mexCallMATLAB(0,NULL,1,&prhs,"sim");
>
> the error that I get is:
> The file name ''example.mdl',35:60' is invalid because it does not have the extension ".mdl" or ".slx".
>
> The problem is that when I use mxCreateString it appends ' characters at the beginning and at the end of my string.
>
> Any idea on how so solve this?
> Your help is greatly appreciated.
>
> Alin


Hi Phil,

Thanks for your response.
The next question will be: how do I do this ?
How do I call the sim function with 2 arguments of different types.
In the command window the call would look like this:

sim('example.mdl',40:90); //the second argument is the time simulation interval

Could you please tell me how to call this function with mexCallMATLAB (the code) ?

Thank you.
Best Regards,

Alin

Subject: mxCreateString usage

From: Steven_Lord

Date: 9 Jul, 2012 14:21:55

Message: 4 of 4



"Alin " <alin.ionascu@live.com> wrote in message
news:jte5vv$jv8$1@newscl01ah.mathworks.com...
> "Alin " <alin.ionascu@live.com> wrote in message
> <jt46uj$jor$1@newscl01ah.mathworks.com>...
>> Hello everyone,
>>
>> I'm trying to start a simulation from within an S-Function which is in my
>> initial simulation.
>> I'm using mxCallMATLAB and the function sim.
>>
>> My problem is the following:
>> I need to execute the sim function with a couple of parameters. I want to
>> pass them as a string and for that I'm using mxCreateString:
>>
>> const char *option = "'example.mdl',35:60";
>> mxArray *prhs = mxCreateString(option);
>> mexCallMATLAB(0,NULL,1,&prhs,"sim");
>>
>> the error that I get is:
>> The file name ''example.mdl',35:60' is invalid because it does not have
>> the extension ".mdl" or ".slx".
>>
>> The problem is that when I use mxCreateString it appends ' characters at
>> the beginning and at the end of my string.
>>
>> Any idea on how so solve this?
>> Your help is greatly appreciated.
>>
>> Alin
>
>
> Hi Phil,
>
> Thanks for your response. The next question will be: how do I do this ?
> How do I call the sim function with 2 arguments of different types.
> In the command window the call would look like this:
>
> sim('example.mdl',40:90); //the second argument is the time simulation
> interval
>
> Could you please tell me how to call this function with mexCallMATLAB
> (the code) ?

Make prhs an array of mxArray*'s. Fill in the first element in that array
with your string and the second with the vector 35:60; the
mxCreateNumericMatrix and mxGetPr functions will be of use to you in
creating that vector. Take a look at the arrayFillGetPr.c example on
mxGetPr's documentation page for an example that you should be able to
adapt.

http://www.mathworks.com/help/techdoc/apiref/mxgetpr.html

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
simulink Phil Goddard 6 Jul, 2012 00:24:09
mxcallmatlab Alin 5 Jul, 2012 10:09:08
sim Alin 5 Jul, 2012 10:09:08
mxcreatestring Alin 5 Jul, 2012 10:09:08
rssFeed for this Thread

Contact us