MATLAB Coder中的C代码生成不支持cell2mat

问题描述 投票:0回答:1

我正在尝试使用MATLAB Codel APP将用MATLAB编写的神经网络函数转换为C函数。但是当我试图转换时,我正在变为

代码生成不支持cell2mat。代码生成不支持arrayfun

我该如何更换这些功能?

我的代码如下所示。输入X是1x2500矩阵,output是1x6矩阵。

完整的代码可以在这个链接qazxsw poi中找到

boneGrwNN

如何为此功能生成C代码?

matlab code-generation matlab-deployment
1个回答
0
投票

您只能从function Y = boneGrwNN(X) x1_step1.ymin = -1; % ===== SIMULATION ======== % Format Input Arguments isCellX = iscell(X); if ~isCellX, X = {X}; end; % Dimensions TS = size(X,2); % timesteps if ~isempty(X) Q = size(X{1},1); % samples/series else Q = 0; end % Allocate Outputs Y = cell(1,TS); % Time loop for ts=1:TS % Input 1 X{1,ts} = X{1,ts}'; Xp1 = mapminmax_apply(X{1,ts},x1_step1); % Layer 1 a1 = tansig_apply(repmat(b1,1,Q) + IW1_1*Xp1); % Layer 2 a2 = softmax_apply(repmat(b2,1,Q) + LW2_1*a1); % Output 1 Y{1,ts} = a2; Y{1,ts} = Y{1,ts}'; end % Format Output Arguments if ~isCellX, Y = cell2mat(Y); end end % ===== MODULE FUNCTIONS ======== % Map Minimum and Maximum Input Processing Function function y = mapminmax_apply(x,settings) y = bsxfun(@minus,x,settings.xoffset); y = bsxfun(@times,y,settings.gain); y = bsxfun(@plus,y,settings.ymin); end % Competitive Soft Transfer Function function a = softmax_apply(n,~) if isa(n,'gpuArray') a = iSoftmaxApplyGPU(n); else a = iSoftmaxApplyCPU(n); end end function a = iSoftmaxApplyCPU(n) nmax = max(n,[],1); n = bsxfun(@minus,n,nmax); numerator = exp(n); denominator = sum(numerator,1); denominator(denominator == 0) = 1; a = bsxfun(@rdivide,numerator,denominator); end function a = iSoftmaxApplyGPU(n) nmax = max(n,[],1); numerator = arrayfun(@iSoftmaxApplyGPUHelper1,n,nmax); denominator = sum(numerator,1); a = arrayfun(@iSoftmaxApplyGPUHelper2,numerator,denominator); end function numerator = iSoftmaxApplyGPUHelper1(n,nmax) numerator = exp(n - nmax); end function a = iSoftmaxApplyGPUHelper2(numerator,denominator) if (denominator == 0) a = numerator; else a = numerator ./ denominator; end end % Sigmoid Symmetric Transfer Function function a = tansig_apply(n,~) a = 2 ./ (1 + exp(-2*n)) - 1; end 生成独立的C代码。如果您真的需要functions supported by code generation代码,因为您的环境不支持Matlab,那么您必须手动转换不支持的函数或使用C才能使用实现相同功能的外部coder.ceval代码。

在您的示例中,您可以使用传统的C替换arrayfun调用。要实现自己的for-loops代码,只需键入cell2mat,以便查看函数的源代码并尝试在代码中复制其逻辑。

© www.soinside.com 2019 - 2024. All rights reserved.