Error running mex file for C code gen: Subscript indices must either be real positive integers or logicals

조회 수: 1 (최근 30일)
I have a function that I coverted to C usingt the coder in double and single successfuly. However when I converted to fixed point using fi-embedded with datatype table, the buildIstumented successed in generating the mex version file, but when I attempted to run the mex version of the function to log data for the showInstrumentation tool , I receive error message above complaining that subscript must be either real positive integers or logicals. The input arguments to the function checks out as embedded fi format. But I cant resolve the issue after doing extensive research on the blogs and mathworks for Asking questions - I see that many complained about this error but the not adequate answers were provided. I use the manual method to covert matlab function into C rather than the app itself. The error is refered to a function that I built to find the maximum from an array of input values .

답변 (1개)

Hari
Hari 2024년 2월 4일
Hi Maya Jubran,
I understand that you are converting a MATLAB function to C code for both double and single precision using MATLAB Coder. However, while converting to fixed-point using the "fi" function and a datatype table, you have encountered an error on running the generated MEX file.
This error occurs there's a mismatch between the expected integer-type indices and the actual indices used in your custom maximum-finding function. MATLAB requires indices to be real positive integers or logicals, and this requirement is strict when dealing with fixed-point arrays.
To address the issue, ensure that all indexing operations within your function use integer-type variables. If you're using fixed-point numbers as indices, convert them to integers first. Here's an example of how you might modify the indexing:
% Assume 'array' is your input fixed-point array and 'index' is a fixed-point number
index = fi(5, 1, 16, 0); % Example fixed-point index
intIndex = int32(index); % Convert to integer for indexing
maxValue = array(intIndex); % Use integer index to access array elements
Also, ensure that any custom functions that you have written for operations like finding the maximum value are compatible with fixed-point arithmetic and indexing.
Refer to the documentation of Fixed-Point Designer for more information on working with fixed-point numbers in MATLAB.
For understanding how to convert fixed-point numbers to integers for indexing, refer to the "fi" function documentation https://www.mathworks.com/help/fixedpoint/ref/fi.html
Hope this helps!

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by