How do I typecast an mwArray to a C++ scalar variable?

2 views (last 30 days)
How do I typecast an mwArray to a C++ scalar variable?
The methods for Extracting Data from an mwArray on page 3-41 of the MATLAB C++ Math Library User's Guide does not seem to work. I added the following code fragment to ex2.cpp at line 24:
mwArray U, S, V;
int32 i;
U=4;
i=U;
and I got the following error messages:
C:\programs\matlabR12\extern\include\cpp\stdexcpt.h(24) : warning C4273: 'strdup' : inconsistent dll
linkage. dllexport assumed.
ex2_2.cpp(30) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type
'class mwArray' (or there is no acceptable conversion)
MBUILD.BAT: Error: Compile of 'ex2_2.cpp' failed.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
There is an error in the MATLAB C++ Math Library User's Guide 2.1 regarding implicit and explicit typecasting. The following codes illustrate how to correctly cast an mwArray to a C++ scalar variable:
int32 i;
double j;
mwArray A = 5;
mwArray B = 25.97;
i = A.Int();
j = B.Double();
This error in the MATLAB C++ Math Library User's Guide will be corrected for the next release of the guide.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!