# Math Help - [Matlab] 2D Sequence Plot in 3D

1. ## [Matlab] 2D Sequence Plot in 3D

Dear Friends,

I am trying to plot a 2D sequence in 3D with the following code, but I dont know why it does not work.
Code:
z=ones(30,30);
for i=1:30
for j=1:30
z(i,j)=sin(i*j);
end
end
x=1:30;
y=1:30;
plot3(x,y,z);
grid on;
box on;
xlabel('x');
ylabel('y');
zlabel('z');
My main idea is to put points at $(x,y,sin(x*y))$ when $x$ and $y$ travels through the integers from $1$ to $30$.

Thanks for the help.

2. Originally Posted by bkarpuz
Dear Friends,

I am trying to plot a 2D sequence in 3D with the following code, but I dont know why it does not work.
Code:
z=ones(30,30);
for i=1:30
for j=1:30
z(i,j)=sin(i*j);
end
end
x=1:30;
y=1:30;
plot3(x,y,z);
grid on;
box on;
xlabel('x');
ylabel('y');
zlabel('z');
My main idea is to put points at $(x,y,sin(x*y))$ when $x$ and $y$ travels through the integers from $1$ to $30$.

Thanks for the help.
Try:

Code:
x=1:30;
y=1:30;

[X,Y]=meshgrid(x,y)
Z=sin(X.*Y);

plot3(X,Y,Z);

3. Originally Posted by CaptainBlack
Try:

Code:
x=1:30;
y=1:30;

[X,Y]=meshgrid(x,y)
Z=sin(X.*Y);

plot3(X,Y,Z);
Ty CB but I have a double sequence (I need to calculate it by iteration).
I could write the following code and it works but I wonder if I can show it as a surface or not (something like meshing but negative parts yellow and positive parts red)?
Code:
z=ones(30,30);
for x=2:30
for y=2:30
z(x,y)=power(-1,y)*z(x-1,y)+2*power(-1,x)*z(x,y-1);
end;
end;
for x=1:30
for y=1:30
if z(x,y)>0
plot3(x,y,z(x,y),'r*');
else
plot3(x,y,z(x,y),'y*');
end
grid on;hold on;
end;
end;
box on;
view(0,90);
xlabel('x');
ylabel('y');
zlabel('z');
Thanks again.