Expected a scalar value. This expression has size [:? x :?].
조회 수: 7 (최근 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
Denis Gurchenkov
2023년 6월 8일
Hi Oliver,
As a quick workaround, just replace "rowStart" with "rowStart(1)" and see if that lets you move forward.
To investigate this issue in more detail, we'd need to have access to reproduction steps. Screenshots do not provide enough information to understand where rowStart is assigned and why the code generator thinks it may be a matrix and not a scalar.
답변 (1개)
Harsh
2024년 10월 12일
Hi Oliver,
You have specified the types of the input variables to the “setAtMatrixRange” function. But since “MatrixIndexRange” is also a user-defined class, you must use property validation to specify the types of all properties of “MatrixIndexRange” class for the code generator to use those specifications. You can define “rowStart” as scalar with size as (1,1) in the properties block of the “MatrixIndexRange” class. You can also add validation function “mustBeNumeric” to ensure datatype is numeric. Below is an example code snippet to show how to do so -
classdef ExampleClass
properties
rowStart (1,1) double {mustBeNumeric} = 0;
end
end
For more information, you can look at the following documentation page: https://www.mathworks.com/help/coder/ug/define-input-properties-using-function-argument-validation-in-matlab-code.html#:~:text=%2Dargs.-,Use%20User%2DWritten%20MATLAB%20Classes%20in%20arguments%20Blocks,-Suppose%20that%20one
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Input Specification에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!