Clear Filters
Clear Filters

Subscript indices must be real positive error

2 views (last 30 days)
I am trying to run a code(part of which is mentioned below) where h,u and x values have been defined separately in the rest of the code.. When I try to run this code to plot piecewise function, it gives me the following error "Subscript indices must either be real positive integers or logicals.
Error in fem51uapprox (line 78) y(c:d-1)=r.^2; %u(2*m-1,1).*w1+u(2*m,1).*w2+u(2*m+1,1).*w3;"
Can anybody please tell me what I am supposed to do to get rid of the error?
r=0:0.01:1;
y=zeros(length(x));
for m=1:n
w1=(1./h).*(r-x(2.*m)).*((2./h).*(r-x(2.*m))-1);
w2=(1-(2./h).*(r-x(2.*m))).*((2./h).*(r-x(2.*m))+1);
w3=(1./h).*(r-x(2.*m)).*((2./h).*(r-x(2.*m))+1);
c=round((m-1)*h*100);
d=round(m*h*100);
y(c:d-1)=r.^2; %u(2*m-1,1).*w1+u(2*m,1).*w2+u(2*m+1,1).*w3;
end
a=0:0.001:1;
b=(1-((1+a).^(3./2)))./3;
plot(r,y,a,b,'b');

Accepted Answer

Matt J
Matt J on 30 Oct 2012
Edited: Matt J on 30 Oct 2012
This line will give c=0 when m=1
c=round((m-1)*h*100);
you cannot use c=0 as an index into y, like you are currently doing in
y(c:d-1)=r.^2;

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!