# MATLAB Matlab 3D plot using arrays in if/else

#### this town

Dear fellows,

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!

Related Math Software Workshop News on Phys.org

"Matlab 3D plot using arrays in if/else"

### Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving