Changing the tick labels in MATLAB for each loop iteration

  • Context: MATLAB 
  • Thread starter Thread starter roldy
  • Start date Start date
  • Tags Tags
    Loop Matlab
Click For Summary
SUMMARY

This discussion focuses on dynamically labeling y-axis tick marks in MATLAB during iterative plotting of multiple curves. The user aims to automate the labeling process to include the format "N{i},{k}" for each curve, where "i" represents the curve index and "k" represents the iteration index. The current approach using the 'set(gca, 'YTickLabel', ...)' function is insufficient due to varying numbers of curves in each iteration. A solution requires creating a custom labeling function that adjusts based on the number of curves plotted in each iteration.

PREREQUISITES
  • Familiarity with MATLAB plotting functions
  • Understanding of for-loops and iteration in programming
  • Knowledge of MATLAB's 'set' function for axis properties
  • Basic understanding of array manipulation in MATLAB
NEXT STEPS
  • Research how to create dynamic tick labels in MATLAB using 'set(gca, 'YTickLabel', ...)'
  • Learn about MATLAB's 'sprintf' function for formatted string output
  • Explore MATLAB's documentation on plotting multiple curves
  • Investigate MATLAB's 'num2str' function for converting numbers to strings
USEFUL FOR

This discussion is beneficial for MATLAB users, data analysts, and researchers who need to automate the labeling of plots with varying numbers of curves across multiple iterations.

roldy
Messages
206
Reaction score
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: 585
  • k=2.jpg
    k=2.jpg
    22.4 KB · Views: 556
  • k=3.jpg
    k=3.jpg
    24.6 KB · Views: 570
Physics news on Phys.org
http://www.mathworks.com/help/techdoc/creating_plots/f6-7929.html#f6-27773
 
Last edited by a moderator:
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.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 5 ·
Replies
5
Views
17K
  • · Replies 5 ·
Replies
5
Views
4K