From: Magnus Croneborg on
When I try to execute this code :

f=@(v,d) sqrt(1-(sin(d./0.1)).^2.*(sin(v)).^2);
for ii = 1:-0.1:0.1
INT(ii) = quad(@(v) f(v,ii),0,1)
end

I get an error message like this :
??? Subscript indices must either be real positive integers or logicals.
Error in ==> lab32 at 9
INT(ii) = quad(@(v) f(v,ii),0,1)

The code works perfect if I use:
for ii = 1:1:10
why does'nt it work when the variables is lower than 1.

Kind regards Magnus Croneborg


From: Walter Roberson on
Magnus Croneborg wrote:
> When I try to execute this code :
>
> f=@(v,d) sqrt(1-(sin(d./0.1)).^2.*(sin(v)).^2);
> for ii = 1:-0.1:0.1
> INT(ii) = quad(@(v) f(v,ii),0,1) end
>
> I get an error message like this :
> ??? Subscript indices must either be real positive integers or logicals.
> Error in ==> lab32 at 9
> INT(ii) = quad(@(v) f(v,ii),0,1)
>
> The code works perfect if I use:
> for ii = 1:1:10
> why does'nt it work when the variables is lower than 1.

Look at where you are assigning the output to. Suppose for example you had
somehow reached ii = 0.7; you would be trying to assign the result of the quad
call to location INT(0.7) . That's not allowed, as array subscripts must be
positive integers.

Try something like this:

ii = 1:-0.1:0.1;
for K = 1:length(ii)
INT(K) = quad(@(v) f(v,ii(K)),0,1)
end
From: Magnus Croneborg on

Walter Roberson <roberson(a)hushmail.com> wrote in message <hplb17$1aa$1(a)canopus.cc.umanitoba.ca>...
> Magnus Croneborg wrote:
> > When I try to execute this code :
> >
> > f=@(v,d) sqrt(1-(sin(d./0.1)).^2.*(sin(v)).^2);
> > for ii = 1:-0.1:0.1
> > INT(ii) = quad(@(v) f(v,ii),0,1) end
> >
> > I get an error message like this :
> > ??? Subscript indices must either be real positive integers or logicals.
> > Error in ==> lab32 at 9
> > INT(ii) = quad(@(v) f(v,ii),0,1)
> >
> > The code works perfect if I use:
> > for ii = 1:1:10
> > why does'nt it work when the variables is lower than 1.
>
> Look at where you are assigning the output to. Suppose for example you had
> somehow reached ii = 0.7; you would be trying to assign the result of the quad
> call to location INT(0.7) . That's not allowed, as array subscripts must be
> positive integers.
>
> Try something like this:
>
> ii = 1:-0.1:0.1;
> for K = 1:length(ii)
> INT(K) = quad(@(v) f(v,ii(K)),0,1)
> end

Thank you Mr Walter Roberson now it works . I have spent several hours struggling with this problem.
Thanks a lot Magnus Croneborg