Error useing axis set
18 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Milu Mihai
am 29 Apr. 2017
Kommentiert: Star Strider
am 29 Apr. 2017
Hello. I needed to make a program for university in witch to i needed to code the finite elementh method useing triangles. I wanted to make the figure in witch i was showing the triangles a bit more visible so i used an axis to make it a bit wider but i get the following error: Error using set Bad property value found. Object Name : axes Property Name : 'YLim' Values must be increasing and non-NaN.
Error in axis>LocSetLimits (line 208) set(ax,...
Error in axis (line 94) LocSetLimits(ax(j),cur_arg);
Error in Metoda_elementului_finit_cu_dreptunghiuri (line 63) axis([a-0.2,b+0.2,c-0.2,d+0.2])
The program is as fallowing:
if true
% function []=Metoda_elementului_finit_cu_dreptunghiuri()
end
a=input('a=');
b=input('b=');
d=input('c=');
c=input('d=');
N=input('N=');
M=input('M=');
Nod=zeros((N+1)*(M+1),3);
Dr=zeros(N*M,4);
x=linspace(a,b,N+1);
y=linspace(c,d,M+1);
k1=0;
for j=1:M+1
for i=1:N+1
k=i+(N+1)*(j-1);
Nod(k,1)=x(i);
Nod(k,2)=y(j);
Nod(k,3)=0;
if((i~=1)&&(i~=N+1)&&(j~=1)&&(j~=M+1))
k1=k1+1;
Nod(k,3)=k1;
end
end
end
display(Nod);
%afisarea
figure(1)
%linii verticale
for i=1:N+1
plot(x(i)*ones(1,M+1),y)
hold on
%pause(0.2)
end
%linii orizontale
for j=1:M+1
plot(x,y(j)*ones(1,N+1))
hold on
%pause(0.2)
end
for k=1:(N+1)*(M+1)
if Nod(k,3)==0
plot (Nod(k,1),Nod(k,2),'*b')
hold on
else
plot(Nod(k,1),Nod(k,2),'or')
hold on
end
axis([a-0.2,b+0.2,c-0.2,d+0.2])
end
%matricea dreptunghiurilor
kT=0;
for j=1:M+1
for i=1:N+1
k=i+(N+1)*(j-1);
if(i<=N)&&(j<=M)
kT=kT+1;
Dr(kT,1)=k;
Dr(kT,2)=k+N+1;
Dr(kT,3)=k+N+2;
Dr(kT,4)=k+1;
end
end
end
display(Dr);
MR=zeros((N-1)*(M-1));
L=zeros((N-1)*(M-1),1);
nd=N*M;
for k=1:nd
xd=zeros(4,1);
yd=zeros(4,1);
for j=1:4
xd(j)=Nod(Dr(k,j),1);
yd(j)=Nod(Dr(k,j),2);
end
D=zeros(4);
for j=1:4
D(1:4,j)=[xd(j)*yd(j);xd(j);yd(j);1];
end
Dinv=inv(D);
A=Dinv(1:4,1);
B=Dinv(1:4,2);
C=Dinv(1:4,3);
Me=zeros(4);
Le=zeros(4,1);
aDr=(xd(3)- xd(1))*(yd(2)-yd(1));
for i=1:4
for j=1:4
R=((A(i)*A(j)*(yd(2)^2 + yd(1)*yd(2) +...
yd(1)^2 + xd(3)^2 + xd(3)*xd(1) + ...
xd(1)^2 )*1/3)+(A(i)*B(j)+A(j)*B(i))...
*(y(2)+y(1))+(A(i)*C(j)+A(j)*C(i))*(x(3)+...
x(1))*1/2 +B(i)*B(j)+C(i)*C(j))*aDr;
Me(i,j)=R;
end
Le(i)=(f(xd(i),yd(i))*aDr/4);
end
display(Me)
display(Le)
for i=1:4
for j=1:4
if((Nod(Dr(k,i),3)~=0) && (Nod(Dr(k,j),3)~=0))
MR(Nod(Dr(k,i),3),(Nod(Dr(k,j),3)))=...
MR(Nod(Dr(k,i),3),(Nod(Dr(k,j),3)))+Me(i,j);
end
if(Nod(Dr(k,i),3)~=0)
L(Nod(Dr(k,i),3))=L(Nod(Dr(k,i),3))+Le(i);
end
end
end
end
display(MR);
display(L);
function[z]=f(x,y)
z=2.*sin(x).*sin(y);
end
end
Thanks in advance!
0 Kommentare
Akzeptierte Antwort
Star Strider
am 29 Apr. 2017
My guess is that the error is in this axis call, since I don’t see any others:
axis([a-0.2,b+0.2,c-0.2,d+0.2])
If you only want to make the axis limits larger, this will probably work:
axlims = [get(gca, 'XLim') get(gca, 'YLim')];
axis(axlims + [-0.2 0.2 -0.2 0.2])
Put those two lines in place of your current axis call. That should solve your problem.
2 Kommentare
Star Strider
am 29 Apr. 2017
My pleasure.
One option is to multiply them by the adjustment vector instead of adding them:
axis(sign(axlims) .* (abs(axlims) .* [1+0.2, 1+0.2, 1+0.2, 1+0.2]))
This works correctly for both positive and negative axis limits. Adjust the offset values (here all 0.2) to get the result you want.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!