Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

A question on axis labeling

  1. Jun 25, 2010 #1
    The x-axis and y-axis are interchanged in the figure by running the following matlab function I wrote.

    Could anyone help me to get it corrected? Thanks in advance for any helpful answer.

    function axislabeling(n)
    x=1:1:n;
    y=1:1:n;

    z=zeros(n,n);

    for i=1:n
    for j=1:n
    z(i,j)=i;
    end
    end
    surf(x,y,z(x,y))

    ylabel('y-axis')
    xlabel('x-axis')
    zlabel('z-axis')
    colorbar
     
  2. jcsd
  3. Jun 26, 2010 #2
    Do you mean you want the function to slant the other way? Just put z(i,j) = j in you loop instead of i. If you simply want to change the labeling, put ylabel('x-axis') and xlabel('y-axis'). Also, a more "Matlab" way of writing that code would be:

    [x y] = meshgrid(1:n);
    z = x;

    figure
    surf(x, y, z)
    xlabel('x-axis')
    ylabel('y-axis')
    zlabel('z-axis')
    colorbar
     
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook