How can I declear a struct array in m file when generating C++ codes through Matlab Coder?

5 visualizaciones (últimos 30 días)
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!

Respuestas (2)

Sunny
Sunny el 12 de Jul. de 2013
change a(:) to a

Mike Hosea
Mike Hosea el 12 de Jul. de 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.

Categorías

Más información sobre MATLAB Coder en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by