Printing out the element values in a mxDouble array (C++ script in Matab)

Hi,
I am using Matlab 2017b and am having trouble printing out the values stored in a mxDouble array.
I have written a mexFunction in a C++ script that takes in a 2-d array as input. Using mxGetPr, I create a pointer of type double * to this array. Let's call this pointer "x."
I try to print out the first element of the array, using the following code:
mexPrintf("x value is%d\n",*x);
However, it appears that the integer printed is address of the value pointed to by x, not the value itself.
How do I print out the value pointed to instead of the address?
Thanks!

 채택된 답변

James Tursa
James Tursa 2019년 5월 31일
편집: James Tursa 2019년 5월 31일

0 개 추천

%d is a decimal integer format for use with short, int, long, etc. This doesn't work with floating point. Try e.g. %f or %g instead.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 C Shared Library Integration에 대해 자세히 알아보기

태그

질문:

2019년 5월 31일

편집:

2019년 5월 31일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by