Please explain Coder run-time errors
1 view (last 30 days)
Show older comments
John Griswold
on 14 Jul 2017
Commented: John Griswold
on 14 Jul 2017
I admit I'm new and ignorant of both Matlab and Coder, but like everybody else, I have a project to do. I'm trying to convert some .m files to .c files so I can use them in an embedded project. I've been provided the code by another engineer. I just have to make it work.
As a .m script, this works well. It runs through Coder without issue. The report, such as it is, says everything is just ducky. When I run the _mex equivalent, I get:
if true
% code
endendTrial>> wrapTo2Pi_mex 4.3
Incorrect class for expression 'lambda': expected 'double' but found 'char'.
Error in wrapTo2Pi_mex
I might be able to figure this out on my own if I knew WHERE in the code the problem occurred.
(I just noticed the (C) Mathworks in the code, so presumably this code is properly constructed, and it does seem to work).
Can anybody decode the error for me? Thanks in advance from someone who will never be as good at Matlab as you are right now.
Herewith the code:
if true
% code
endendfunction lambda = wrapTo2Pi(lambda)
%wrapTo2Pi Wrap angle in radians to [0 2*pi]
%
% lambdaWrapped = wrapTo2Pi(LAMBDA) wraps angles in LAMBDA, in radians,
% to the interval [0 2*pi] such that zero maps to zero and 2*pi maps
% to 2*pi. (In general, positive multiples of 2*pi map to 2*pi and
% negative multiples of 2*pi map to zero.)
%
% See also wrapToPi, wrapTo180, wrapTo360.
% Copyright 2007-2008 The MathWorks, Inc. % $Revision: 1.1.6.1 $ $Date: 2008/12/22 23:50:53 $
positiveInput = (lambda > 0); lambda = mod(lambda, 2*pi); lambda((lambda == 0) & positiveInput) = 2*pi;
Accepted Answer
Ryan Livingston
on 14 Jul 2017
Edited: Ryan Livingston
on 14 Jul 2017
wrapTo2Pi_mex(4.3) is the right syntax to pass a double precision number to wrapTo2Pi_mex. The code wrapTo2Pi_mex 4.3 passes the char array '4.3' similar to a command-line executable.
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!