得到错误:dlen = uint32(0);

时间:2014-11-06 16:09:46

标签: matlab uint32

我不知道为什么但是我收到了这个错误:

Error in mr_lsbpex (line 3)
dlen = uint32(0) ; 

Output argument "a" (and maybe others) not assigned during call to "E:\path\mr_lsbpex.m>mr_lsbpex"

我已经测试了" dlen = uint32(0);"在matlab环境中(在这个函数之外),一切都很好。这是我的代码:

function a = mr_lsbpex ( r, p ) 
% extract from an array
dlen = uint32(0) ; 
s = size (r) ; 

rnd = rand (s(1),s(2)) ; 
rd = 32 ; 
rl = s(2) ; 

for i=1:s(2)
    if rnd(1,i)<rd/rl 
        d = bitget (round(r(1,i)/p),1); 
        dlen = bitset (dlen,rd,d); 
        rd = rd -1 ; 
    end
    rl = rl -1 ;
end

if (dlen > 10000000 )
    clear a ; 
    return ;
end

a = uint8(zeros(dlen,1)) ; 
rd = double(dlen * 8) ; 
rl = double(s(1)*s(2)-s(2)) ; 
for i=2:s(1)
    for j=1:s(2)
        if rnd(i,j)<rd/rl
            d = bitget (round(r(i,j)/p) ,1) ; 
            a = z_set_bit (a,rd,d) ; 
            rd = rd - 1 ;
        end
        rl = rl - 1 ; 
    end
end

1 个答案:

答案 0 :(得分:2)

请记住:a需要返回 ALLWAYS


错误不在该特定行中,而是在“整个”函数本身中。

你的问题是Matlab认为a它不会被创建。实际上在某些情况下可能无法创建。

函数开头的以下行应该是技巧

a=0; % well, or a=NaN; or whatever you want to return 

此外,clear a中不要if (dlen > 10000000 )