简体   繁体   English

MATLAB 到 C 代码

[英]MATLAB to C-code

I am following MathWorks guide to converting MATLAB code to C-code.我正在按照 MathWorks 指南将 MATLAB 代码转换为 C 代码。 The first step is to enter第一步是输入

%#codegen %#codegen

after every function that I want converted to C-code, however doing so has given me the following prompt on the code below.在我想转换为 C 代码的每个函数之后,但是这样做在下面的代码中给了我以下提示。

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"代码生成仅支持“varargin”和“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 . B - 是bwboundaries 图像处理工具箱函数输出 It is a P-by-1 cell array , where P is the number of objects and holes.它是一个P×1 元胞数组,其中 P 是对象和孔洞的数量。 Each cell in the cell array contains a Q-by-2 matrix.元胞数组中的每个元胞都包含一个 Q×2 矩阵。 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. Q 是对应区域的边界像素数。

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 - 用绿色轮廓绘制对象的边界,同时是一个大小为 1 X length(B) 的矩阵,保存边界的值,如下所示:

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) stats - 使用图像处理工具箱中的regionprops函数获取的19x1 结构数组,其中包含以下字段:MajorAxisLength 和 MinorAxisLength(对象的)

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 .只有 MATLAB 和 Image Processing Toolbox 中的一部分函数支持代码生成 - Image Processing Toolbox 支持代码生成

  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:在我的 for 循环中,我有一个语句,它有相同的错误:

y(i) = k;

I introduced a temporary storage variable u and modified my code to:我引入了一个临时存储变量 u 并将我的代码修改为:

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

I suggest you do the same for your variable lanes.我建议你对可变车道做同样的事情

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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