Azzera filtri
Azzera filtri

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

4 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

SK
SK il 18 Ott 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;

Più risposte (0)

Categorie

Scopri di più su Labels and Annotations in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by