Changing the tick labels in MATLAB for each loop iteration

  • MATLAB
  • Thread starter roldy
  • Start date
  • Tags
    Loop Matlab
In summary, the conversation discusses how to label the y-axis x marks for a plot with "i" number of curves, using the set gca tick label function. The challenge is that the plotting of the curves repeats for "k" times, with the number of curves potentially changing in each iteration. The desired labeling format includes the letter "N" followed by the "ith" curve and the iteration number. The suggested solution is to create an array based on "i" and label the y tick marks using this format. However, manual labeling may be required for each iteration.
  • #1
roldy
237
2
Suppose that I am plotting some data that corresponds to "i" different functions. So on the plot I have "i" number of curves on one plot. Instead of using a legend, I would like to label the y-axis x mark that corresponds to the function. I can do this using the set gca tick label function. Here's the catch, the plotting of the "i" number of curves repeats for "k" times. Each "kth" iteration, the number of curves on the plot may or may not be the same as the previous "k" iteration. I can create an array based on "i" which would label the y tick marks but I want to include the letter "N" followed by the "ith" curve". See attached figures. Right now I have to do the labeling manually for each iteration.
 

Attachments

  • k=1.jpg
    k=1.jpg
    21.5 KB · Views: 500
  • k=2.jpg
    k=2.jpg
    22.4 KB · Views: 477
  • k=3.jpg
    k=3.jpg
    24.6 KB · Views: 484
Physics news on Phys.org
  • #2
http://www.mathworks.com/help/techdoc/creating_plots/f6-7929.html#f6-27773
 
Last edited by a moderator:
  • #3
I've tried using that and it doesn't work for what I need. I need the letter "N" then followed by the basis function number "i" then "," followed by the iteration number "k". So for the first iteration starting at the top most line I'll have something like N0,1, N1,1, N2,1...For the second iteration I'll have something like N0,2, N1,2, N2,2...However I can't just set the tick label because for each iteration, I might have a different number of basis functions to label.
 

What is the purpose of changing tick labels in a MATLAB for loop?

The purpose of changing tick labels in a MATLAB for loop is to dynamically update the axis labels on a graph or plot during each iteration of the loop. This can be useful for displaying changing data or parameters on a graph.

How do I change the tick labels in a MATLAB for loop?

To change the tick labels in a MATLAB for loop, you can use the "set" function and specify the properties of the axis you want to modify. For example, you can use "set(gca,'XTickLabel',labels)" to change the x-axis tick labels to a list of labels defined in the "labels" variable.

Can I change the tick labels for both the x-axis and y-axis in a MATLAB for loop?

Yes, you can change the tick labels for both the x-axis and y-axis in a MATLAB for loop by using the "set" function for each axis separately. For example, you can use "set(gca,'XTickLabel',x_labels)" and "set(gca,'YTickLabel',y_labels)" to change the tick labels for both axes.

Is it possible to change the tick labels to non-numeric values in a MATLAB for loop?

Yes, it is possible to change the tick labels to non-numeric values in a MATLAB for loop. You can use a cell array to define the labels and then assign it to the "XTickLabel" or "YTickLabel" property of the axis using the "set" function.

Can I change the tick labels to be rotated or aligned differently in a MATLAB for loop?

Yes, you can change the tick labels to be rotated or aligned differently in a MATLAB for loop by using the "XTickLabelRotation" and "XTickLabelAlignment" properties of the axis. These properties can be modified using the "set" function to change the orientation and alignment of the tick labels.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
575
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
14
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Programming and Computer Science
Replies
16
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
2K
Back
Top