1

使用 MATLAB coder 从 m 文件生成 c++ 代码并调用 ac 函数 ompmex.c 时出现以下错误

C 函数调用总是返回标量值,但这里需要一个非标量值。

我的代码是:

function [D,gamma] = DSGD2(X,H) %#codegen

   [Xr,Xc]=size(X);
   [Hr,Hc]=size(H);

   D=zeros(Hr,Hc,'double');
   D=X(:,11:210);
   d1=sqrt(sum(D.*D)); D=D./repmat(d1,Xr,1);

   beta=zeros(Xr,Xc,'double');

   beta=coder.ceval('ompmex',H,X,H'*H,200);

任何人都可以帮助解决这个问题。我在网上没有得到有效的答案

4

1 回答 1

0
function [D,gamma] = DSGD2(X,H) %#codegen

   [Xr,Xc] = size(X);
   [Hr,Hc] = size(H);

   D = zeros(Hr,Hc,'double');
   D = X(:,11:210);
   d1 = sqrt(sum(D.*D)); 
   D = D./repmat(d1,Xr,1);

   % coder.ceval is tricky. I recommand to use it only if the function is
   % created by c-coder too (and not as mex function!)! you need a c executable
   % or a c library (generated before you trigger codegen for DSGD2). 
   % further more, ceval can not handle multiple
   % outputs. as a workaround, always use structs for output - and for
   % input too!
   s = struct('beta',(zeros(Xr,Xc,'double')));
   % make it work in matlab too and call ompmex function
   if coder.target('MATLAB')
       s = ompmex(H,X,H'*H,200);
   else
       coder.ceval('ompmex_initialize')
       s = coder.ceval('ompmex',H,X,H'*H,200);
       coder.ceval('ompmex_terminate')
   end
   % read out stuct value
   beta = zeros(Xr,Xc,'double');
   beta = s.beta;

   gamma = 0; % not given by you, but c-coder needs it. so change to what ever you need
end
于 2014-08-16T14:00:17.100 回答