Please explain Coder run-time errors

1 回表示 (過去 30 日間)
John Griswold
John Griswold 2017 年 7 月 14 日
コメント済み: John Griswold 2017 年 7 月 14 日
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;
  1 件のコメント
John Griswold
John Griswold 2017 年 7 月 14 日
Please forgive the formatting errors. Apparently I'm ignorant of this subject as well.

サインインしてコメントする。

採用された回答

Ryan Livingston
Ryan Livingston 2017 年 7 月 14 日
編集済み: Ryan Livingston 2017 年 7 月 14 日
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.
  1 件のコメント
John Griswold
John Griswold 2017 年 7 月 14 日
Thank you so much. If we ever meet, you get to smack me on the forehead! John

サインインしてコメントする。

その他の回答 (0 件)

製品

Community Treasure Hunt

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

Start Hunting!

Translated by