在matlab中访问函数声明

Access to function declaration in matlab

matlab 中的卷积函数是conv()。我的问题是如何获得函数本身的实际实现?

如果您想了解 conv() 的工作原理或制作您自己的 conv 函数版本,您可以随时输入

open conv

在命令中window。然后您可以查看原始函数并(如有必要)将其保存在新名称下并使用您编辑过的版本。

有两种方式:

  1. 方法一

    当您实现 conv() 或任何函数(用户定义的或内置的)时,只需右键单击该函数并单击 打开 以查看函数脚本。

  2. 方法二

    在命令window中写入open conv()conv() 可以是任意函数


卷积函数:

function c = conv(a, b, shape)
%CONV Convolution and polynomial multiplication.
%   C = CONV(A, B) convolves vectors A and B.  The resulting vector is
%   length MAX([LENGTH(A)+LENGTH(B)-1,LENGTH(A),LENGTH(B)]). If A and B are
%   vectors of polynomial coefficients, convolving them is equivalent to
%   multiplying the two polynomials.
%
%   C = CONV(A, B, SHAPE) returns a subsection of the convolution with size
%   specified by SHAPE:
%     'full'  - (default) returns the full convolution,
%     'same'  - returns the central part of the convolution
%               that is the same size as A.
%     'valid' - returns only those parts of the convolution 
%               that are computed without the zero-padded edges. 
%               LENGTH(C)is MAX(LENGTH(A)-MAX(0,LENGTH(B)-1),0).
%
%   Class support for inputs A,B: 
%      float: double, single
%
%   See also DECONV, CONV2, CONVN, FILTER, XCORR, CONVMTX.
%
%   Note: XCORR and CONVMTX are in the Signal Processing Toolbox.


%   Copyright 1984-2013 The MathWorks, Inc.

if ~isvector(a) || ~isvector(b)
  error(message('MATLAB:conv:AorBNotVector'));
end

if nargin < 3
    shape = 'full';
end

if ~ischar(shape) && ~(isstring(shape) && isscalar(shape))
  error(message('MATLAB:conv:unknownShapeParameter'));
    end
    if isstring(shape)
        shape = char(shape);
    end
    
    % compute as if both inputs are column vectors
    c = conv2(a(:),b(:),shape);
    
    % restore orientation
    if shape(1) == 'f' || shape(1) == 'F'  %  shape 'full'
        if length(a) > length(b)
            if size(a,1) == 1 %row vector
                c = c.';
            end
        else
            if size(b,1) == 1 %row vector
                c = c.';
            end
        end
    else
        if size(a,1) == 1 %row vector
            c = c.';
        end
    end
end
if isstring(shape)
    shape = char(shape);
end

% compute as if both inputs are column vectors
c = conv2(a(:),b(:),shape);

% restore orientation
if shape(1) == 'f' || shape(1) == 'F'  %  shape 'full'
    if length(a) > length(b)
        if size(a,1) == 1 %row vector
            c = c.';
        end
    else
        if size(b,1) == 1 %row vector
            c = c.';
        end
    end
else
    if size(a,1) == 1 %row vector
        c = c.';
    end
end

更新:

这与问题无关。不管怎样,你想计算卷积积分,但 matlab 中的 conv() 函数定义是:

w = conv(u,v) returns 向量 u和v的卷积。如果u和v是多项式系数的向量,对它们进行卷积相当于乘以两个多项式。

请考虑这是 离散 卷积并且不会为您提供结果的公式。如果您需要结果的公式,请使用符号工具箱来计算 Convolution Integral.


看到这个convolution