Why do I have difficulty in using the << operator with the ramp function with mwArray?

1 view (last 30 days)
Why do I have difficulty in using the << operator with the RAMP function with the mwArray interface?
The following code segment produces an error when compiled to a stand-alone and executed using MBUILD:
1. Create test.cpp from the following C++ code:
#include "matlab.hpp"
void main()
{
mwArray x;
x=ramp(-10,0.1,9);
cout<<x<<endl;
}
2. Compile it using mbuild:
mbuild -setup %select VC++
mbuild -v test.cpp
3. Execute the code:
!test
from the MATLAB prompt.
I should receive the following error message:
abnormal program termination
[
However, if I replace the code in test.cpp with the following:
#include "matlab.hpp"
void main()
{
mwArray x;
x=ramp(-10,0.1,11);
cout<<x<<endl;
}
and run steps 2 and 3 again, I receive a listing of the contents of 'x' rather than the error message.
The problem occurs when the last argument to RAMP is less than 10 (the absolute value of the first variable).

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This is a bug in the MATLAB C/C++ Math Library 2.2 (R12.1) that is being investigated by our development staff.
The current work around is to explicitly print the variables out in a FOR loop.
#include "matlab.hpp"
void main()
{
mwArray x;
x=ramp(-10,0.1,9);
for(int i = 0; i<190; i++)
cout<<x(i)<<endl;
}

More Answers (0)

Community Treasure Hunt

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

Start Hunting!