Filter löschen
Filter löschen

MATLAB coder - how can I add fields to an existing struct?

4 Ansichten (letzte 30 Tage)
Sheida
Sheida am 17 Okt. 2014
Beantwortet: SK am 18 Okt. 2014
Hi, I want to be able to add a field to an existing struct. Here is a simplified example:
function [Prm] = Testangles(input)
Prm.NumAngles = input;
Prm.Angles = linspace(0,360,Prm.NumAngles);
When I try to generate code, I get the error message: "??? This structure does not have a field 'Angles'; new fields cannot be added when structure has been read or used."
What would be the best way to deal with this problem?
Thanks! Sheida

Akzeptierte Antwort

SK
SK am 18 Okt. 2014
There are many restictions in converting Matlab to C via coder. Coder emits C code on the fly as it parses the .m file. It looks like it assumes that the struct has been fully defined once any of its fields have been used. It would then emit the corresponding C code that defines the C-struct. Since, in C, the whole structure has to be defined in one place, no further changes to the struct are possible.
You will need to get the results beforehand in temporary variables and then put them in the struct.
function [Prm] = Testangles(input)
numangles = input;
angles = linspace(0, 360, numangles);
Prm.NumAngles = numangles;
Prm.Angles = angles;

Weitere Antworten (0)

Kategorien

Mehr zu Labels and Annotations finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by