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
anotherdave
  • 6,656
  • 4
  • 34
  • 65

1 Answers1

2

Remember: a needs to be returned ALLWAYS!


The error is not in that specific line, but in the "whole" function itself.

Your problem is that Matlab thinks that a its not going to be created. And actually in some case it may not be created.

The following line in the beginning of your function should do the trick

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

Additionally, don't clear a in if (dlen > 10000000 ).

Ander Biguri
  • 35,140
  • 11
  • 74
  • 120