How can I declear a struct array in m file when generating C++ codes through Matlab Coder?
Mostra commenti meno recenti
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!
Risposte (2)
Sunny
il 12 Lug 2013
0 voti
Mike Hosea
il 12 Lug 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.
Categorie
Scopri di più su MATLAB Coder in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!