How can I declear a struct array in m file when generating C++ codes through Matlab Coder?
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Matlab Coder reports an error when generating C++ codes from matlab codes:
??? Conversion to struct from double is not possible.
Error in ==> structtest Line: 5 Column: 14
I guess data type absence leads to this error.But hoa can I declear a as an empty struct array?
Notes :
function below is just an example. in my application, I don't know how long 'a' will be.
the struct member 'image' is an uint8 matrix with non fixed size.
my Matlab version is 2012a.
matlab codes is as below:
function a = structtest()
a = [];
for i = 1 : 10
b.image = 1;
a = [a(:); b];
end
end
Thanks!
0 commentaires
Réponses (2)
Mike Hosea
le 12 Juil 2013
I would use repmat. Initially MATLAB Coder did not support empty struct arrays. Unfortunately, I don't remember when that restriction was lifted. This works in 13a
function a = tstruct
% coder.varsize('a',[inf,1],[true,false]);
b = struct('image',1); % Define the structure type.
a = repmat(b,0,1);
for i = 1:10
b.image = 1;
a = [a;b];
end
The varsize line is commented out because it isn't needed. However, if you have an upper bound in mind on how long the array can be, you can substitute it for the inf there.
0 commentaires
Voir également
Catégories
En savoir plus sur MATLAB Coder dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!