MATLAB Function always infers outputs as doubles

1 回表示 (過去 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 Center および File ExchangeCode Generation についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by