简体   繁体   中英

MATLAB to C-code

I am following MathWorks guide to converting MATLAB code to C-code. The first step is to enter

%#codegen

after every function that I want converted to C-code, however doing so has given me the following prompt on the code below.

function lanes=find_lanes(B,h, stats)
% Find the regions that look like lanes
%#codegen

lanes = {};
l=0;
    for k = 1:length(B)
    metric = stats(k).MajorAxisLength/stats(k).MinorAxisLength;
    %testlane(k);
    %end
    %function testlane(k)
        coder.inline('never');
        if metric > 5 & all(B{k}(:,1)>100)
            l=l+1;
            lanes(l,:)=B(k);
        else
            delete(h(k))
        end
    end
end

around the curly braces:

code generation only supports cell operations for "varargin" and "varargout"

Another prompt says

Code generation does not support variable "lanes" size growth through indexing

where lanes is mentioned for the second time.

The input Arguments for the function are:

B - Is the output of the bwboundaries Image Processing toolbox function . It is a P-by-1 cell array , where P is the number of objects and holes. Each cell in the cell array contains a Q-by-2 matrix. Each row in the matrix contains the row and column coordinates of a boundary pixel. Q is the number of boundary pixels for the corresponding region.

h - plots the boundaries of the objects with a green outline while being a matrix of size 1 X length(B), holding the values of the boundaries like so like so:

h(K)=plot(boundary(:,2), boundary(:,1), 'g', 'LineWidth', 2);//boundary(:,1) - Y coordinate, boundary(:,2) - X coordinate.

stats - 19x1 struct array acquired using the regionprops function from the Image Processing toolbox with fields: MajorAxisLength and MinorAxisLength (of the object)

I would really appreciate any input you can give in helping me clear this error. Thanks in Advance!

Few points about your code generation -

  1. Only a subset of functions in MATLAB and Image Processing Toolbox support code generation - Image Processing Toolbox support for code generation .

  2. Cell arrays do not support code generation yet - Cell array support .

  3. In your code, it seems like your variable is growing ie the initial size of the array is not able to support your workflow. You should follow code generation for variable sized inputs .

I had a similar error ie code generation does not support variable size growth through indexing . Inside my for loop I had a statement as such which had the same error:

y(i) = k;

I introduced a temporary storage variable u and modified my code to:

u = y;
u(i) = k;
y = u;

I suggest you do the same for your variable lanes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM