Matlab coder generated mex function

조회 수: 8 (최근 30일)
Jane Jean
Jane Jean 2013년 7월 20일
댓글: Lenin Cruz 2019년 8월 30일
Hi!
I have recently generated a mex function using Matlab coder. However, the mex function stops at one line of the code where 'max' is used. The 'max' is only one of the functions from eml toolbox. Below is the error message displayed:
If the working dimension of MAX or MIN is variable in length, it must not have
zero length at runtime.
Error in eml_min_or_max>eml_extremum (line 73)
eml_invariant(size(x,dim) > 0, ...
Error in eml_min_or_max (line 18)
extremum = eml_extremum(varargin{:});
Error in max (line 16)
maxval = eml_min_or_max('max',varargin{:});
Error in Initialization (line 78)
max_elev = max(E_32_ELEV(1,AvailPRN_init));
Thanks for your help!

채택된 답변

Ryan Livingston
Ryan Livingston 2013년 7월 22일
Could it be possible that the array which is being passed to MAX has an empty dimension when you are running the MEX?
The error suggests that for a call like:
max(A)
where A is variable-sized in its first non-singleton dimension, "dim" then,
size(A,dim)
should not be zero.
As an example, suppose that A is 1-by-:5-by-10 meaning that A is variable-sized in the second dimension with an upper bound of 5 for size(A,2). In this case, "dim" would be 2 since size(A,1) is 1.
If at runtime A is 1-by-0-by-10 then you will see this error.
You could do something like:
if isempty(A)
maxVar = A;
else
maxVar = max(A);
end
in your MATLAB code to prevent this error. Alternatively, if you are specifying "dim" explicitly in your call to MAX you could use:
if size(A,dim) == 0
maxVar = A;
else
maxVar = max(A,[],dim);
end
The reason for this check in code generation is to ensure that the output of MAX has a constant value for size(max(A), dim). Functions like BSXFUN and others then depend upon this information.
  댓글 수: 1
Lenin Cruz
Lenin Cruz 2019년 8월 30일
Whatf if, dim is variable?

댓글을 달려면 로그인하십시오.

추가 답변 (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