Warning:Size vector should be a row vector with integer elements.

  • Follow


Hello,
I've a problem when i try to run the function posted below: 

function[k]= sampling_sinep(samp_step,n_a,n_b,n_c)


dim=(2/samp_step)+1;
s_v=zeros(dim,1);
m=1;
for k=-1:samp_step:1
    s_v(m,1)=sin((2*pi*k));
    m=m+1;
end
hist(s_v);
k=kurtosis(s_v);


When passed as a paramater samp_step=.00001 or less ,the function works correctly,but I've this warning: Warning: Size vector should be a row vector with integer elements. (at 13: s_v=zeros(dim,1))

Somebody have any idea?

Thanks 
Alessio
0
Reply Alessio 12/9/2010 8:50:20 AM

"Alessio Nervi" <alessio.gastaldo@gmail.com> wrote in message <idq58c$kc6$1@fred.mathworks.com>...
> Hello,
> I've a problem when i try to run the function posted below: 
> 
> function[k]= sampling_sinep(samp_step,n_a,n_b,n_c)
> 
> 
> dim=(2/samp_step)+1;
> s_v=zeros(dim,1);
> m=1;
> for k=-1:samp_step:1
>     s_v(m,1)=sin((2*pi*k));
>     m=m+1;
> end
> hist(s_v);
> k=kurtosis(s_v);
> 
> 
> When passed as a paramater samp_step=.00001 or less ,the function works correctly,but I've this warning: Warning: Size vector should be a row vector with integer elements. (at 13: s_v=zeros(dim,1))
> 
> Somebody have any idea?
> 
> Thanks 
> Alessio

As the message says, you need the size element of zeros to be an integer (i.e. dim). There's no guarantee that it will be from your code, although it could be that the values you intend to use for samp_step will always be okay.

You could either add a function in the defintion of dim which will convert to an integer (like floor), or you could add a check that 2/samp_step is an integer where you define dim with some default behaviour or error if it doesn't.

e.g.

dim = floor(2/samp_step + 1);

or

dim = 2/samp_step + 1;
if mod(dim,1) ~= 0
  then 
     error('myFun:sampStep', 'The inverse of the sampling step argument must be a mutliple of 2')
  end

I've not got a working matlab handy to test this, so I can't guarantee that the error catching will be enough to suppress the warning (or that it will work exactly as written) but I prefer it since it doesn't allow for mistaken inputs to generate surprising outputs.

Hazel

P.S. 
"When passed as a paramater samp_step=.00001 or less ,the function works correctly"
Really? What about 0.0000097 ....
0
Reply Hazel 12/9/2010 10:00:06 AM


"Hazel " <haz.duncan@tiscali.co.uk> wrote in message <idq9b6$b9s$1@fred.mathworks.com>...
> "Alessio Nervi" <alessio.gastaldo@gmail.com> wrote in message <idq58c$kc6$1@fred.mathworks.com>...
> > Hello,
> > I've a problem when i try to run the function posted below: 
> > 
> > function[k]= sampling_sinep(samp_step,n_a,n_b,n_c)
> > 
> > 
> > dim=(2/samp_step)+1;
> > s_v=zeros(dim,1);
> > m=1;
> > for k=-1:samp_step:1
> >     s_v(m,1)=sin((2*pi*k));
> >     m=m+1;
> > end
> > hist(s_v);
> > k=kurtosis(s_v);
> > 
> > 
> > When passed as a paramater samp_step=.00001 or less ,the function works correctly,but I've this warning: Warning: Size vector should be a row vector with integer elements. (at 13: s_v=zeros(dim,1))
> > 
> > Somebody have any idea?
> > 
> > Thanks 
> > Alessio
> 
> As the message says, you need the size element of zeros to be an integer (i.e. dim). There's no guarantee that it will be from your code, although it could be that the values you intend to use for samp_step will always be okay.
> 
> You could either add a function in the defintion of dim which will convert to an integer (like floor), or you could add a check that 2/samp_step is an integer where you define dim with some default behaviour or error if it doesn't.
> 
> e.g.
> 
> dim = floor(2/samp_step + 1);
> 
> or
> 
> dim = 2/samp_step + 1;
> if mod(dim,1) ~= 0
>   then 
>      error('myFun:sampStep', 'The inverse of the sampling step argument must be a mutliple of 2')
>   end
> 
> I've not got a working matlab handy to test this, so I can't guarantee that the error catching will be enough to suppress the warning (or that it will work exactly as written) but I prefer it since it doesn't allow for mistaken inputs to generate surprising outputs.
> 
> Hazel
> 
> P.S. 
> "When passed as a paramater samp_step=.00001 or less ,the function works correctly"
> Really? What about 0.0000097 ....


Thanks Hazel,
everything you said I was of help!
I have never considered the possibility of assigning not multiple values of two.

I understand my error!

Thanks
Alessio
0
Reply Alessio 12/9/2010 10:16:05 AM

On 09/12/10 2:50 AM, Alessio Nervi wrote:

> dim=(2/samp_step)+1;
> s_v=zeros(dim,1);

> When passed as a paramater samp_step=.00001 or less ,the function works
> correctly,but I've this warning: Warning: Size vector should be a row
> vector with integer elements. (at 13: s_v=zeros(dim,1))

There is no exact binary floating point representation for 1/10^N for 
N>0 . 2 divided by the floating point representation of 1/10^N is not 
necessarily going to be an exact integer.
0
Reply Walter 12/9/2010 5:05:01 PM

3 Replies
990 Views

(page loaded in 0.527 seconds)

Similiar Articles:













7/20/2012 12:31:39 PM


Reply: