Subscript indices must be real positive error

3 次查看(过去 30 天)
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');

采纳的回答

Matt J
Matt J 2012-10-30
编辑:Matt J 2012-10-30
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;

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by