Expected a scalar value. This expression has size [:? x :?].

16 次查看(过去 30 天)
I used MATLAB coder to generate c++ code for my project. The coder app shows the following report:
This "setAtMatrixRange" function is a method of a class "ImageWrapper", which wraps up an image(matrix) and provides some public interfaces to operate on the image it manages.
The "setAtMatrixRange" method sets positions of the property "img"(a matrix) with values specified by the "valueMatrix" argument and at places specified by the "matrixRange" argument. The "matrixRange" is an instance of the MatrixIndexRange class, which records the "range" of the row and column indexes of a matrix.
The coder complained that "rowStart" was expected to be a scalar value, but the expression has size [:? × :?].
To check if "rowStart" is scalar, I added these "isscalar" function checking to print messages to me if any is not scalar.
I first run the script that calls my entry point function in MATLAB to see if everything was right. And it was, the command window is clean.
Next, I run the same script, but this time in the "Check for run-time issues" section in the MATLAB coder app, and the error came out.
I am totally confused and lost.
  3 个评论
zzm oliver
zzm oliver 2023-6-12
Thank you for replying. I solved the problem by specifying with "(1)" to force extracting the first element, although matlab coder later complained about more places where it expected a scalar but meets size[:? × :?] and I fixed them using the same way. Finally I successfully tested the generated dll, and it worked! Still I just don't understand why it may happen.


回答(0 个)


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




Community Treasure Hunt

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

Start Hunting!

Translated by