Dear fellows,(adsbygoogle = window.adsbygoogle || []).push({});

I am trying to plot a 3D graph, determining the x and y values using an array and the z values using if/else. This is the code I am playing with but I can't get it to work:

xmin=-1000;

xmax=1000;

division=1.0;

num=((xmax-xmin)/division)+1;

for i=1:(num/2);

x(i)=i-(num/2);

for k=1:(num/2);

y(k)=k-(num/2);

for j=1:10:(num/2);

u(j)=j-num/2;

v(j)=j+6-num/2;

if ((x(i)>=u(j))&&(x(i)<=v(j))&&(x(i)<1000)&&(x(i)>0)&&(y(k)>0)&&(y(k)<1000)) |((x(i)>-1000)&&(x(i)<0)&&(y(k)>-1000)&&(y(k)<1000))|((x(i)>0)&&(x(i)<1000)&&(y(k)>-1000)&&(y(k)<0));

z(i,k)=1.0;

else

z(i,k)=0.0;

end

end

end

end

surf(x,y,z)

I am very new to this so any help would be very valuable, thanks!

**Physics Forums | Science Articles, Homework Help, Discussion**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Matlab 3D plot using arrays in if/else

Can you offer guidance or do you also need help?

**Physics Forums | Science Articles, Homework Help, Discussion**