How to replace Nonscalar struct for Matlab Coder error?

조회 수: 2 (최근 30일)
WanYu
WanYu 2020년 5월 7일
댓글: David Fink 2020년 5월 11일
Hi,
When I'm trying to transform my Matlab code to C, this error appeared yet I don't know how to modify it as it necessary in my function.
%% Remove small objects.
binaryImage = imclearborder(binaryImage);
binaryImage = bwareaopen(binaryImage, 100);
%% Invert the binarized image
% binaryImage = ~ binaryImage;
%% Get centroid on image
stats = regionprops(binaryImage, 'Centroid'); % acting on the cleaned image
centroids = cat(1, stats.Centroid);
x1 = centroids(1,1);
y1 = centroids(1,2);
x3 = centroids(3,1);
y3 = centroids(3,2);
The error " Directly accessing field or property of nonscalar struct or object not supported for code generation" showed at
centroids = cat(1, stats.Centroid);
How I can resolved it as it is necessary for my function.

채택된 답변

David Fink
David Fink 2020년 5월 8일
centroids = cat(1, stats.Centroid);
is just concatenating the centroid row vectors in the first dimension (vertical), which can be replaced by a loop:
numRegions = numel(stats);
centroids = zeros(numRegions, numel(stats(1).Centroid)); % pre-initialize to set size
for region = 1:numRegions
centroids(region, :) = stats(region).Centroid; % write one row at a time
end
We are looking to allow the original syntax in a future release of MATLAB Coder!
  댓글 수: 3
WanYu
WanYu 2020년 5월 10일
Hi David,
This error came out after that,
"
The invoked code did not call entry-point function
"
What should I do or how to resolve this error?
David Fink
David Fink 2020년 5월 11일
It looks like the test code that calls the entry-point errored out - "View errors" should give the specifics.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Coder에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by