How can I declear a struct array in m file when generating C++ codes through Matlab Coder?
조회 수: 5 (최근 30일)
이전 댓글 표시
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
답변 (2개)
Mike Hosea
2013년 7월 12일
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
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!