Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Problem with mxGetData

Subject: Problem with mxGetData

From: Elnaz

Date: 8 Apr, 2013 22:39:09

Message: 1 of 3

Hi all,

I'm trying to read a real valued double with:
double x;
x = mxGetData(prhs[0]);

When compiling in MATLAB I receive:
error C2440: 'type cast' : cannot convert from 'void *' to 'double'

I just want to pass a double value to my function and read it. How can I do this?

Thanks,
Elnaz

Subject: Problem with mxGetData

From: James Tursa

Date: 8 Apr, 2013 23:06:05

Message: 2 of 3

"Elnaz " <ebsadeghian@gmail.com> wrote in message <kjvgud$om0$1@newscl01ah.mathworks.com>...
> Hi all,
>
> I'm trying to read a real valued double with:
> double x;
> x = mxGetData(prhs[0]);
>
> When compiling in MATLAB I receive:
> error C2440: 'type cast' : cannot convert from 'void *' to 'double'
>
> I just want to pass a double value to my function and read it. How can I do this?
>
> Thanks,
> Elnaz

mxGetData returns a (void *) type and you are trying to stuff it into a double, which doesn't make sense. Try this instead:

x = *mxGetPr(prhs[0]);

or

double *p;
p = mxGetPr(prhs[0]); // then use *p for the double value itself.

or if you insist on using mxGetData:

double *p;
p = (double *) mxGetData(prhs[0]);


This all assumes that prhs[0] actually contains a non-empty double array.

James Tursa

Subject: Problem with mxGetData

From: Elnaz

Date: 8 Apr, 2013 23:50:12

Message: 3 of 3

Thanks James. This works.
Elnaz

Tags for this Thread

No tags are associated with this thread.

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.

Contact us