필터 지우기
필터 지우기

MATLAB Function always infers outputs as doubles

조회 수: 3 (최근 30일)
Lucas Ritzdorf
Lucas Ritzdorf 2024년 4월 17일
편집: Kiran Kintali 2024년 4월 21일
First, context: I'm attempting to generate HDL code from a Simulink model, which includes a MATLAB Function block. The relevant function is:
function [output, valid] = demux(input)
%#codegen
num_outputs = 24;
% Memory element: demultiplexed outputs
persistent demuxed;
if isempty(demuxed)
demuxed = zeros(num_outputs, 1, 'like', input);
end
% Assign from "input" to a single element of "demuxed" here... trimmed for length
% Commit actual values
output = demuxed(1:num_outputs, 1);
In my Simulink model, both input and output are sfix24_En23 types (fixed-point, signed, 24 bits total, 23 bits fractional):
I've tried to hint to MATLAB that output should be fixed-point as well, even including this line at the beginning of the function:
output = fi(zeros(num_outputs, 1), true, 24, 23);
This explicitly includes my fixed-point parameters, which isn't great for maintainability, but would be acceptable for now in order to allow the model to compile.
However, in this and every other case I've tested, the Simulink console complains that Inferred type ('double') for data 'output' does not match back propagated type ('embedded.fi (sfix24_En23)') from Simulink. Is there a way to make MATLAB realize that the output isn't actually a double?

답변 (1개)

Kiran Kintali
Kiran Kintali 2024년 4월 21일
편집: Kiran Kintali 2024년 4월 21일
It would be hard to reproduce with the partial information above.
Sharing a sample MATLAB function supported syntax for HDL code generaton using HDL Coder. The sample code shows how to define output type, size/dimensions, complexity prior to assigning the output value. Hope it is helpful.
Please share your sample MATLAB function block for further assistance.

카테고리

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

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by