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 Center および File ExchangeLogical についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by