Errors using codegen when using structure as return values of function
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi folks,
I'm with Northrop Grumman.
Here's a function with a structure for input values (PhyInit), and a return value that I intend to be a structure:
I have a Test Bench that calls this code and it runs successfully. But when I compile with codegen, I get an error:
This structure does not have a field 'Waveform'; new fields cannot be added when structure has been read or used.
This structure does not have a field 'decDelay'; new fields cannot be added when structure has been read or used.
function [TxReturn] = PhyTxMlx(PhyInit) %#codegen
dataIn = PhyInit.data;
% Initialization variables are in PhyInit structure
% tPoly = poly2trellis(PhyInit.constrlen,PhyInit.genpoly); % codegen
tPoly = poly2trellis([5 4],[23 35 0; 0 5 13]);
dataEnc = convenc(dataIn,tPoly);
dataSymbolsIn = bit2int(dataEnc,PhyInit.BitsPerSymbol);
IQMod = qammod(dataSymbolsIn,PhyInit.M);
% TxReturn.rrcFilter =
% rcosdesign(PhyInit.rolloff,PhyInit.filtlen,PhyInit.sps); codegen
% constants
TxReturn.rrcFilter = rcosdesign(0.25,10,4); % codegen needs constants
txSignal = upfirdn(IQMod,TxReturn.rrcFilter,4,1);
%
% Return Values from this function
%
% TxReturn = struct; % create structure for return values
TxReturn.Waveform = txSignal; % return IQ complex waveform
TxReturn.decDelay = 10; % return filter delay for BER report
end
1 comentario
Bill Chou
el 23 de Jun. de 2023
Hello Dr. Kurt,
I'm with Product Marketing for Coder products including MATLAB Coder. I'd like to make sure we're able to help answer your questions in this thread and the other one you recently posted.
Could you reach out to me via matlab-coder-expert@mathworks.com? I can check with our Northrop Grumman account team to make sure we're able to help you along.
Thanks!
Bill Chou
Product Marketing, Code Generation
Respuestas (1)
Ryan Livingston
el 23 de Jun. de 2023
The issue that Coder is flagging is that you have something like
someStruct.field1 = value;
use(someStruct.field1);
% This line is what Coder is complaining about because someStruct was used
% above
someStruct.field2 = value;
In particular, for your code I'd suggest rewriting to
function [TxReturn] = PhyTxMlx(PhyInit) %#codegen
dataIn = PhyInit.data;
% Initialization variables are in PhyInit structure
% tPoly = poly2trellis(PhyInit.constrlen,PhyInit.genpoly); % codegen
tPoly = poly2trellis([5 4],[23 35 0; 0 5 13]);
dataEnc = convenc(dataIn,tPoly);
dataSymbolsIn = bit2int(dataEnc,PhyInit.BitsPerSymbol);
IQMod = qammod(dataSymbolsIn,PhyInit.M);
% TxReturn.rrcFilter =
% rcosdesign(PhyInit.rolloff,PhyInit.filtlen,PhyInit.sps); codegen
% constants
% Ryan: Don't write into the struct and then read it here to avoid
% Coder limitations. Use a temporary rrcFilter in the interim.
rrcFilter = rcosdesign(0.25,10,4); % codegen needs constants
txSignal = upfirdn(IQMod,rrcFilter,4,1);
%
% Return Values from this function
%
% TxReturn = struct; % create structure for return values
% Ryan: Now write the values into the output struct
TxReturn.rrcFilter = rrcFilter;
TxReturn.Waveform = txSignal; % return IQ complex waveform
TxReturn.decDelay = 10; % return filter delay for BER report
end
2 comentarios
Ver también
Categorías
Más información sobre Applications en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!