What is the cause of the error message "FIMATH mismatch:Property 'ProductWordLength'" here?

조회 수: 1 (최근 30일)
I get the error message
FIMATH mismatch:Property 'ProductWordLength': 16 ~= 32
from the following action code in a state transition table:
y = fi(10,0,32,10,'ProductMode','SpecifyPrecision','ProductWordLength',32,'ProductFractionLength',10)^x;
where x is defined as:
fixdt(0,8,5)
y is defined as:
fixdt(0,32,10)
The 16 seems to come frome the native number of bits in the hardware implementation details.
Following to this. Is there a short way to just calculate 10^x in the precision of y in StateFlow?

답변 (1개)

Yash
Yash 2024년 8월 23일
Hi Torsten,
The error you're encountering suggests a mismatch in the "ProductWordLength" property when performing the computations. The fi object you are creating for "y" specifies a ProductWordLength of 32, but somewhere in the computation, a ProductWordLength of 16 is being used, likely due to the default fimath settings or hardware constraints.
To calculate (10^x) with the precision of "y" in Stateflow, you can ensure the fimath properties are consistent across your calculations. Here's a way to do this:
  1. Define a consistent fimath object: Create a fimath object with the desired properties and apply it to all fixed-point operations.
  2. Use the fimath object in your computation: Ensure that your calculations are using this fimath object.
Here's an example of how you can achieve this:
% Define the value of x (example value, replace with actual input)
x_value = 3; % Example: x = 3
% Create a fixed-point object for x with the specified type
x = fi(x_value, 0, 8, 5);
% Define a fimath object with consistent properties for the calculation
myFimath = fimath('ProductMode', 'SpecifyPrecision', ...
'ProductWordLength', 32, ...
'ProductFractionLength', 10, ...
'SumMode', 'SpecifyPrecision', ...
'SumWordLength', 32, ...
'SumFractionLength', 10);
% Set the fimath property of x
x.fimath = myFimath;
% Create a fixed-point object for the base number 10
base = fi(10, 0, 32, 10, 'fimath', myFimath);
% Calculate 10^x with the precision of y
y = base^x;
% Display the result
disp(['10^', num2str(x_value), ' = ', num2str(y)]);
10^3 = 1000
Adjust the "x_value" to your specific needs or ensure that "x" is correctly defined elsewhere in your code. This approach should help resolve the fimath mismatch error and allow you to compute (10^x) using the desired precision.

카테고리

Help CenterFile Exchange에서 Fixed-Point Designer에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by