While using coder to convert matlab to c getting error - Subscripting into an empty matrix is not supported and dataToBoxNo 7 Undefined function or variable 'S1'. The first assignment to a local variable determines its class.

1 visualizzazione (ultimi 30 giorni)
Hello
I am using coder for first time. I am running into errors and I am not able to resolve. The code is the following.
function [S] = dataToBoxNo(megData, i, mn, mx, nPart, nDim, tau)
S = 0;
for j = 0:nDim-1
S1 = (fix((megData(i + j * tau) - mn)/((mx - mn) / nPart)))*nPart^j;
S = S + S1;
end
end
The error messages are
dataToBoxNo
6
Subscripting into an empty matrix is not supported.
2
dataToBoxNo
7
Undefined function or variable 'S1'. The first assignment to a local variable determines its class.
Can anyone please give hint as to what is to be done? I have couple other codes with same issue. This would shed light on how to resolve those. Thank you very much.
Chitra

Risposta accettata

Walter Roberson
Walter Roberson il 21 Giu 2015
Use
S1 = 0;
before the loop so that the compiler knows the size and datatype of S1.
For the first bit, about indexing into an empty matrix: at least one of the calls made to this routine is passing in a matrix that is known to be empty.
  5 Commenti

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by