Pregunta

A software library originally written for MATLAB, comprising of MATLAB and C source files, is being ported to Octave. The C code uses the MATLAB MEX file interface. The library works without error on MATLAB, but not on Octave. The C source is closed and I don't have access to it, but someone kindly compiled it for me.

The following Octave code

Y=ones(size(X)) + X;

fails with the error

Subscript indices must be either positive integers or logicals.

X is a matrix returned by the MEX module.

I've already verified that ones and size are referring to the builtin functions and not overwritten by some local variables.

How can I fix this?

EDIT Breaking down into steps:

S=size(X);
O=ones(S);
X+O;

gives the above error on the last line, the addition. The whos command outputs this:

octave:13> whos O X
Variables in the current scope:

   Attr Name        Size                     Bytes  Class
   ==== ====        ====                     =====  =====
        O         512x512                  2097152  double
        X         512x512                  2097152  double

Total is 524288 elements using 4194304 bytes
¿Fue útil?

Solución

The error you report has no reason to be. I can't figure out what it may be doing. If I generate the X matrix you report, it all works fine:

X = rand (512, 512);
S = size (X);
O = ones (S);
X+O;

I don't know how you confirmed that you were using the builtin functions, so can you check that this works:

X = rand (512, 512);
S = builtin ("size", X);
O = builtin ("ones", S);
X+O;

Or could it be that the mex file someone compile for you somehow overloads the plus operator for double? Since you don't have the source for it, I'd suggest you do the following. After calling the mex function, save X, exit, and load it in a new Octave session. Check that the error disappeared, and if not, share the file with us so that we can at least try to reproduce it.

X = your_closed_source_mex (...);
save -binary data.dat X
exit();

Then start a new Octave session:

load -binary data.dat
whos X # confirm that X is loaded
X = rand (512, 512);
S = size (X);
O = ones (S);
X+O;
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top