Correcting Axis Labeling in MATLAB Function | Need Help

  • MATLAB
  • Thread starter forumfann
  • Start date
  • Tags
    Axis
In summary, the x-axis and y-axis are reversed in the figure using a MATLAB function. To correct it, the labeling can be changed by using the functions ylabel() and xlabel(). Alternatively, the code can be rewritten in a more efficient way using meshgrid().
  • #1
forumfann
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
 
Physics news on Phys.org
  • #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
 

Related to Correcting Axis Labeling in MATLAB Function | Need Help

1. Why is axis labeling important in scientific research?

Axis labeling is important in scientific research because it provides clear and accurate information about the variables being measured in a graph or chart. This allows other researchers to understand and interpret the data correctly, and also helps to avoid any potential confusion or misinterpretation.

2. How do you determine the appropriate axis labels for a graph?

The appropriate axis labels for a graph are determined by considering the variables being plotted and their units of measurement. The labels should clearly indicate what is being measured on each axis and in what unit, making it easier for the reader to understand the data being presented.

3. Can the axis labels be changed after a graph has been created?

Yes, axis labels can be changed after a graph has been created. Most graphing software allows for the editing of axis labels, and this can be done by selecting the axis label and typing in the desired label or unit.

4. What are some common mistakes to avoid when labeling axes?

Some common mistakes to avoid when labeling axes include using unclear or confusing labels, not including units of measurement, and not starting the axis at zero when it is necessary. It is also important to make sure the axis labels are legible and not too small or crowded.

5. Is it necessary to include axis labels in every graph or chart?

Yes, it is necessary to include axis labels in every graph or chart. This ensures that the data is accurately represented and easily understood by other researchers. Without axis labels, the graph may be confusing or misleading, making it difficult for others to replicate or build upon the research.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
741
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
Back
Top