可生成的matlab函数中的对象数组

Array of objects in generable matlab function

在 simulink 模型中,我有一个 matlab 功能块。在函数内部,我想以与代码生成兼容的方式创建一个对象数组。

我的问题与此处回答的问题类似:Construct an array of objects in MATLAB

问题是"compatible with code generation"部分。

当我尝试使用 repmatmatlab returns 时:

Arrays of objects are not supported for code generation.

当我尝试使用我看到的对象数组时:

Recursive calls are not allowed. Function 'dummyClass.dummyClass' participated in a recursive call.

请在下面找到我的代码 运行:

内嵌matlab函数

function y = fcn(u)
%#codegen
x = [1 2 3];
% %% repmat way
% aa = dummyClass(x(1));
% aaArray = repmat(aa,1,3);   
%% array of objects
aa = dummyClass(x);

y = u;

class 文件

classdef dummyClass    
    properties
        value
    end

    methods
        function obj = dummyClass(value)
           %% array of objects
            if nargin~=0
                m = size(value,1);
                n = size(value,2);
                obj(m,n) = dummyClass;
                for i = 1:m
                   for j = 1:n
                      obj(a,b).value = value(a,b);
                   end
                end
            end
% %% repmat
%             obj.value = value;
        end
    end

end

取消注释

从 MATLAB R2017a 开始,无法使用 MATLAB Coder 或 Simulink Coder 创建与代码生成兼容的对象数组。

正如第一条错误消息所说,“arrays of objects are not supported for code generation”- 您尝试创建它们的任何特定方式都没有问题,只是根本不支持它们。

MathWorks 可能会在未来的版本中引入此功能,但目前还没有。