Correcting Axis Labeling in MATLAB Function | Need Help

  • Context: MATLAB 
  • Thread starter Thread starter forumfann
  • Start date Start date
  • Tags Tags
    Axis
Click For Summary
SUMMARY

The forum discussion addresses the issue of interchanged x-axis and y-axis labels in a MATLAB function. The user provided a function named axislabeling that generates a surface plot but incorrectly labels the axes. A solution was offered to correct the axis labeling by swapping the ylabel and xlabel commands. Additionally, a more efficient MATLAB coding approach using meshgrid was suggested to streamline the function.

PREREQUISITES
  • Familiarity with MATLAB programming
  • Understanding of surface plots in MATLAB
  • Knowledge of the meshgrid function
  • Basic grasp of axis labeling in MATLAB visualizations
NEXT STEPS
  • Learn how to use the meshgrid function in MATLAB
  • Explore MATLAB's surface plotting capabilities
  • Research best practices for axis labeling in MATLAB
  • Study MATLAB's function syntax and structure for improved coding efficiency
USEFUL FOR

MATLAB users, data scientists, and engineers looking to improve their data visualization skills and correct axis labeling in surface plots.

forumfann
Messages
24
Reaction score
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
 
Physics news on Phys.org
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
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 10 ·
Replies
10
Views
3K
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K