MATLAB Function always infers outputs as doubles
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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?
0 Kommentare
Antworten (1)
Kiran Kintali
am 21 Apr. 2024
Bearbeitet: Kiran Kintali
am 21 Apr. 2024
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.
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!