A question on axis labeling

  • Thread starter forumfann
  • Start date
  • #1
24
0
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
 

Answers and Replies

  • #2
166
0
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
 

Related Threads on A question on axis labeling

Replies
2
Views
2K
Replies
7
Views
90K
  • Last Post
Replies
2
Views
661
  • Last Post
Replies
2
Views
638
Replies
2
Views
4K
  • Last Post
Replies
7
Views
688
Replies
1
Views
13K
Replies
6
Views
7K
Replies
1
Views
742
Replies
11
Views
4K
Top