Problem building C++ static library: "MATLAB expected a scalar"

Dear all,
I am converting some MATLAB code into a C++ static library using the MATLAB Coder. The compiler gives me an error on a line where I compare a scalar to another scalar
if Sm_user == 0
do something
end
However, MATLAB thinks that the variable scalar is in fact non-scalar and therefore the IF statement cannot be evaluated.
I have attached an image showing the pertinent code along with the build report. pair_lo, pair_hi and amps are all defined as 1x:inf arrays of class Double.
cycleMin = pair_lo(pos);
would usually be a scalar because pos is a position in the array amps. However, in the event that pos refers to more than one element in amps, cycleMin and cycleMax are redefined in the two IF statements to make sure they're scalar. Since Sa_user and Sm_user and defined from other scalars, they themselves are scalars. However, MATLAB seems to think that Sm_user is not.
How can I convince the coder that Sm_user isalways scalar?
Many thanks,
Louis Vallance

 채택된 답변

Louis Vallance
Louis Vallance 2014년 4월 23일
For anyone who also has this problem, I've solved it. It's a simple matter of pre-allocating the variables. For example:
pos = some definition % could be 1x?
if length(pos) > 1
pos2 = zeros(1, 1);
pos2(1) = pos(1);
end

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 MATLAB Coder에 대해 자세히 알아보기

질문:

2014년 4월 23일

답변:

2014년 4월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by