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 次查看(过去 30 天)
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

采纳的回答

Walter Roberson
Walter Roberson 2015-6-21
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 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by