Effacer les filtres
Effacer les filtres

Subscript indices must be real positive error

2 vues (au cours des 30 derniers jours)
Sandeep
Sandeep le 30 Oct 2012
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');

Réponse acceptée

Matt J
Matt J le 30 Oct 2012
Modifié(e) : Matt J le 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;

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by