0

I don't know why but I am getting this error:

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"

I have tested "dlen = uint32(0) ;" in matlab enviorment (outside of this function) and everything was OK. Here is my code:

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
4

1 回答 1

2

请记住:a需要始终退回


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

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

函数开头的以下行应该可以解决问题

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

另外,不要clear aif (dlen > 10000000 ).

于 2014-11-06T16:18:17.193 回答