Results 1 to 3 of 3

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

  1. #1
    Senior Member bkarpuz's Avatar
    Joined
    Sep 2008
    From
    R
    Posts
    481
    Thanks
    2

    Exclamation [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.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by bkarpuz View Post
    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);
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Senior Member bkarpuz's Avatar
    Joined
    Sep 2008
    From
    R
    Posts
    481
    Thanks
    2

    Exclamation

    Quote Originally Posted by CaptainBlack View Post
    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.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. 3D plot of z = (Matlab)
    Posted in the Math Software Forum
    Replies: 4
    Last Post: July 14th 2011, 09:22 PM
  2. matlab plot function
    Posted in the Math Software Forum
    Replies: 4
    Last Post: May 26th 2010, 08:03 AM
  3. help me to plot this equation in Matlab....
    Posted in the Math Software Forum
    Replies: 1
    Last Post: April 23rd 2009, 10:38 PM
  4. matlab 3D-4D graphic plot
    Posted in the Math Software Forum
    Replies: 6
    Last Post: October 25th 2008, 03:53 AM
  5. MatLab Plot
    Posted in the Math Software Forum
    Replies: 1
    Last Post: August 2nd 2008, 11:59 AM

Search Tags


/mathhelpforum @mathhelpforum