When I assign a one-dimensional SAFEARRAY as input to my COM library, generated from MATLAB Builder for COM 1.1.4 (R14SP2), why is the output a two-dimensional array?

2 views (last 30 days)
I generated a COM library, myCOM_1_0.dll, with MATLAB Builder for COM 1.1.4 (R14SP2) and am using it in my C++ code to create a console program, myprogram.exe.
The console log of myprogram.exe is as follows
C:\ Test\Debug>myprogram.exe
Extracting CTF archive. This my take a few seconds, depending on the size of your application. Please wait...
...CTF archive extraction complete.
dimension of input is 1.
lower bound of input is 0.
upper bound of input is 4.
dimension of output is 2.
lower bound of output in 1st dimension is 1.
upper bound of output in 1st dimension is 1.
lower bound of output in 2nd dimension is 1.
upper bound of output in 2nd dimension is 5.
output(1) = 11.000000
As shown above, when I assign a one-dimensional safearray as input to myCOM_1_0.dll, the output is a two-dimensional array. Also, the lower bound of the input starts from 0, but for the output it starts from 1.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This is expected behavior in MATLAB. Safearray is just an array with bounds checking. Hence, the output array returned behaves exactly like a typical array in MATLAB, meaning it will be one-based and will have the same dimensions as the matrix in the workspace.
For example, execute the following set of commands at the MATLAB command prompt:
a = [1 2 3]
size(a)
ndims(a)
The array returned from the above code in MATLAB will have two dimensions; one dimension will be of length 1. The returned array will look like
a[1,1] = 1
a[1,2] = 2
a[1,3] = 3
reflecting its form in MATLAB.

More Answers (0)

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Products


Release

R14SP2

Community Treasure Hunt

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

Start Hunting!