24小时热门版块排行榜    

查看: 609  |  回复: 0

H_LG

银虫 (正式写手)

[求助] 求高手将一个M函数转换成mex文件或mex语法编写的c代码

如题,将以下程序进行转换
因为这个程序在我的matlab程序中多次调用,很耗时。
求高手解答或指点。
谢过!

function [A]=OMPerr(D,X,errorGoal)%#codegen
% ========================================================
% Sparse coding of a group of signals based on a given dictionary and specified representation
% error to get.
% input arguments: D - the dictionary
%                           X - the signals to represent
%                           errorGoal - the maximal allowed representation error
% output arguments: A - sparse coefficient matrix.
% ========================================================
[n,P]=size(X);
[n,K]=size(D);
E2 = errorGoal^2*n;
maxNumCoef = n/2;
A = zeros(size(D,2),size(X,2));
% h=waitbar(0,'OMP on each example ...');
for k=1:1,
%     waitbar(k/P);
    a=[];
    x=X(:,k);
    residual=x;
    indx = [];
    a = [];
    currResNorm2 = sum(residual.^2);
    j = 0;
    while currResNorm2>E2 && j < maxNumCoef,
        j = j+1;
        proj=D'*residual;
        pos=find(abs(proj)==max(abs(proj)));
        pos=pos(1);
        indx(j)=pos;
        a=pinv(D(:,indx(1:j)))*x;
        residual=x-D(:,indx(1:j))*a;
        currResNorm2 = sum(residual.^2);
    end;
    if (~isempty(indx))
        A(indx,k)=a;
    end
end;
% close(h);
return;[ 来自科研家族 控制&图像家族 ]
回复此楼

» 本帖附件资源列表

  • 欢迎监督和反馈:小木虫仅提供交流平台,不对该内容负责。
    本内容由用户自主发布,如果其内容涉及到知识产权问题,其责任在于用户本人,如对版权有异议,请联系邮箱:xiaomuchong@tal.com
  • 附件 1 : OMPerr.m
  • 2011-12-23 17:13:13, 1.17 K

» 猜你喜欢

邢台学院学生论坛:http://www.xtxybbs.com
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

智能机器人

Robot (super robot)

我们都爱小木虫

相关版块跳转 我要订阅楼主 H_LG 的主题更新
信息提示
请填处理意见