HolySaint 发表于 2010-11-11 19:57

问个函数返回值的问题

function = rsgenpoly(N, K, varargin)
%RSGENPOLYGenerator polynomial of Reed-Solomon code.
%   GENPOLY = RSGENPOLY(N,K) returns the narrow-sense generator polynomial of a
%   Reed-Solomon code with codeword length N and message length K.The codeword
%   length N must have the form 2^m-1 for some integer m between 3 and 16.The
%   output GENPOLY is a Galois row vector that represents the coefficients of
%   the generator polynomial in order of descending powers.The narrow-sense
%   generator polynomial is (X-alpha)*(X-alpha^2)*...*(X-alpha^(N-K)), where
%   alpha is a root of the default primitive polynomial for the field GF(N+1).
%
%   GENPOLY = RSGENPOLY(N,K,PRIM_POLY) is the same as the syntax above, except
%   that PRIM_POLY specifies the primitive polynomial for GF(N+1) that has alpha
%   as a root.PRIM_POLY is an integer whose binary representation indicates
%   the coefficients of the primitive polynomial in order of descending powers.
%   To use the default primitive polynomial, set PRIM_POLY to [].
%
%   GENPOLY = RSGENPOLY(N,K,PRIM_POLY,B) returns the generator polynomial
%   (X-alpha^B)*(X-alpha^(B+1))*...*(X-alpha^(B+N-K-1)), where B is an integer
%   and alpha is a root of PRIM_POLY.
%
%    = RSGENPOLY(...) returns T, the error-correction capability of
%   the code.
%
%   Examples:
%      g= rsgenpoly(7,3)       % Narrow-sense generator polynomial
%      g2 = rsgenpoly(7,3,13)    % Narrow-sense generator polynomial,
%                              %   with respect to primitive polynomial
%                              %   D^3+D^2+1
%      g3 = rsgenpoly(7,3,[],4)% Use b=4
%
%   See also GF, RSENC, RSDEC.



%    Copyright 1996-2007 The MathWorks, Inc.
%    $Revision: 1.4.4.2 $$Date: 2007/09/14 15:57:43 $


% Initial checks
error(nargchk(2,4,nargin,'struct'));

% Number of optional input arguments
nvarargin = nargin - 2;

% Error-correcting capability
t = floor((N-K)/2);
t2 = N-K;
m = log2(N+1);
def_primpoly = 1;
b = 1;% Default : narrow-sense

if any([~isscalar(N) | ~isscalar(K) | floor(N)~=N | floor(K)~=K])
    error('comm:rsgenpoly:InvalidNK','N and K must be positive scalar integers.');
end

if t2<1
    error('comm:rsgenpoly:NLessThanK','N must be larger than K.');
end

if m~=floor(m) | m<3 | m>16
error('comm:rsgenpoly:InvalidN','N must equal 2^m-1 for some integer m between 3 and 16.')
end

if ~isempty(varargin)

    prim_poly = varargin{1};

    % Check prim_poly
    if isempty(prim_poly)
      if ~isnumeric(prim_poly)
            error('comm:rsgenpoly:InvalidDefaultPrim_Poly','To use the default PRIM_POLY, it must be marked by [].');
      end
    else
      if ~isscalar(prim_poly)
            error('comm:rsgenpoly:Prim_PolyNotScalar','PRIM_POLY must be a scalar integer.');
      end
      % ZZZ add isprimitive once it's available
      def_primpoly = 0;
    end

    if nvarargin==2
      b = varargin{2};
      if ~isscalar(b) | floor(b)~=b
            error('comm:rsgenpoly:BNotAnInt','B must be an integer scalar.');
      end
    end
end

% Alpha is the primitive element of this GF(2^m) field
if def_primpoly == 1
    alpha = gf(2,m);
else
    alpha = gf(2,m,prim_poly);
end


genpoly = 1;
for k=mod(b+,N)
    evalc('genpoly = conv(genpoly,);');
end



大家帮忙看看
我想获得这个返回值,即将他赋给一个变量POLY
rsgenpoly(31,25)
POLY = ;

试了改了一下没有成功
多谢啊

HolySaint 发表于 2010-11-11 23:22

>> rsgenpoly(31,25)

ans = GF(2^5) array. Primitive polynomial = D^5+D^2+1 (37 decimal)

Array elements =

         1          17          26          30          27          30          24

默认返回这个

HolySaint 发表于 2010-11-11 23:26

>> POLY=rsgenpoly(31,25);
>> POLY

POLY = GF(2^5) array. Primitive polynomial = D^5+D^2+1 (37 decimal)

Array elements =

         1          17          26          30          27          30          24

>> POLY(1)

ans = GF(2^5) array. Primitive polynomial = D^5+D^2+1 (37 decimal)

Array elements =

         1

>> POLY(1)+POLY(2)

ans = GF(2^5) array. Primitive polynomial = D^5+D^2+1 (37 decimal)

Array elements =

          16怎么把POLY变成普通的向量呢?

Happy99 发表于 2010-11-12 00:59

专业不懂, 稍微搜下help, 没试成
建议考量简化下

HolySaint 发表于 2010-11-12 09:23

回复 4 # Happy99 的帖子

不是太懂,所以说的也不是太明白哈,我在研究一下
就是把poly变量变成普通的变量,你看那个加法就知道了

qibbxxt 发表于 2010-11-12 09:46

只需要在函数的末尾加上genpoly=genpoly.x;因为gf是个结构体,可以用open gf查看代码
运行的结果:>> pp=rsgenpoly(31,25)

pp =

         1          17          26          30          27          30          24

HolySaint 发表于 2010-11-12 09:57

回复 6 # qibbxxt 的帖子

多谢哈,成功了

Happy99 发表于 2010-11-12 11:13

建议不要修改源程序,直接使用POLY=rsgenpoly(31,25); pp=POLY.x即可

昨晚第一时间亦是朝这个方向! 但没试对fieldname, 又一时没找到查询函数(应用fieldnames, 原少个s字)
原来那些值是'x'!
请教gf class的cmd win显示好像与结构体不同, 结构体直接就有fieldname显示!?

HolySaint 发表于 2010-11-12 15:47

回复 8 # Happy99 的帖子

恩,我也是在我的程序里直接提取的,没有改gf域的那个函数,多谢哈~~
页: [1]
查看完整版本: 问个函数返回值的问题