MATLAB Matlab 3D plot using arrays in if/else

  • Thread starter this town
  • Start date
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!
 

Want to reply to this thread?

"Matlab 3D plot using arrays in if/else" You must log in or register to reply here.

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
Top