Matlab dynamically add legend. Adding a legend manually for a plot generated by.

Matlab dynamically add legend MATLAB legend() Function in for-loop- add entry in every loop. I tried solutions like this but those do not work for Hi Paul, thanks for the answer. My stored variable “ beats_Local_var1_W1” value contains the incremental values (in this case includes 5000, 5500,. Learn more about legend You can pass labels to the legend function in a cell array so you can create that dynamically as e. I want to add legend dynamically on each subplot & the number of subplot is not predefined, it may be 10 or 20 or 25 like that. " x = 0:360; axis([0 360 -1 1]) I use "line" to plot each point, make a legend for the colors across the top, and then attempt to make separate legend on the right for the markers by placing another axis on top of the first one. Populating a Legend Dynamically. In 2017a, when I make some plots and add a legend, then add subsequent plots, the legend is updated with new unwanted entries generically labeled 'data1', 'data2', etc. Matlab Populating a Legend Dynamically. Hot Network Questions Meaning of Second line of Shakespeare's Sonnet 66 Three years ago I explained how we can use a couple of undocumented hidden properties of the legend in order to add a legend title (the legend object had no Title property back then – this was only added in a later Matlab release, perhaps as a result of my post). Store your data in a structure and utilize dynamic field references. Matlab multiple entries in one legend line. I am creating a graph iteratively from various data sets, and I try to add legend to it, but it fails. mat" and so Hi, my task would be to have a legend which is update dynamically as I loop over some data extracted from different files and I add them to a same plot, for instance. (I did do some more looking at it and there is no easy way to simply add an additional label to an existing legend that I could come up with anyway that was any Hi, my task would be to have a legend which is update dynamically as I loop over some data extracted from different files and I add them to a same plot, for instance. With pyplot. Matlab: variable legend in plot. However the padding can be adjusted with the new IconColumnWidth property on legend. Hi Paul, thanks for the answer. Here is an how to add legend automatically : for exmaple this is my code . mat file I load before and I am getting data from. Dynamic legend in selectable plot using checkbox in GUI. You can add the legend manually and set the color and marker as per your own. (I did do some more looking at it and there is no easy way to simply add an additional label to an existing legend that I could come up with anyway that was any When I want to create my Legend, I don't have access to all the handle of my figures. According to the post that you mention, you have to define that you will need i different colours in your plot. Amcharts - Checkbox legend. What I'm Skip to content. First, you don't need plot3, you can achieve the same figure with plot, and probably the long legend is because of that. The . Add matrix to structure column without using for loop? 2. If you are working with a fairly recent version of Matlab (> R2014b I think) then you can edit an existing legend if you keep the handle to it: figure; hAxes = gca; I try to add the legend which should, according to my example, output: a red square with the word fruit and ; a green square with the word veggie. Graph Legend MATLAB For Loop. 5. there's no hold on to add to an existing axes and How to dynamically allocate labels to a legend?. For example, you don't need to set Populating a Legend Dynamically. just change the line of plot to that:. legend(loc = 'upper left') matplotlib. If you copy an object containing a dynamic property, the dynamic property is not copied. Notes: 1. 3 different colors x 3 (solid lines, dotted lines etc). How to dynamically create and update a legend ?. I know how to make this manually by typing the legends in the Matlab code. 'MarkerFaceColor' has to be adjusted separately; you can define a list of colors initially and loop over them. mat" and so Any ideas on how to create a dynamically changing legend? The code is included below: AOI_unique=unique(AOI); %for each of those unique AOI's, plot the row vs. Then I could alter the legend text position (also in icons). Add custom legend without any relation to the graph. FontSize = 14. > In legen Plot - add legend individually. Amro. You can use the text function to add text to a Matlab figure. This happened because the icons in the legend are not exclusively markers. Use this command if you are updating graphics objects in a loop and do not need to see every update Jiro's pick this week is legappend by Chad Greene. The size of the matrix is 3xN, N is accepted with input. Your plot sentence will then be: plot(z,var{i},'DisplayName',str{i},'Color', colors(i,:)); Update. Something like this (it was made in OriginLab): Following to this link Add custom legend without any relation to the graph I can add some text using plot(NaN,NaN,'display','add info here2', 'linestyle', 'none'). Learn more about 2d plots, for loops, legends. I want to add legend to the right of the colorbar, and I tried doing so using the legend function, but it is not shown using the text function places it outside the printanle area. Follow edited Jun 29, 2012 at 0:53. How do I add additional items to an existing dynamic legend? You can add additional items to an Thanks Azzi this works, but in my case this will go inside a function which will be executed for each plot, then ' hl=legend('leg1') ' should be executed only the first time that the function is executed. In your case, instead of passing the legend captions to the legend function, you'll need to use them as input arguments to the plot function:. Learn more about dynamic legend, plotting, for loop, nested for loop MATLAB nested for loop MATLAB. Hello, I am struggling on how to create a custom label for a series of plots I am doing at the moment (I know how to change the right axis colour). Legend I'd like to add two legends to a plot in MATLAB. When I call the legend() functions as legend('', 'cosine'); instead of adding the empty third parameter, indeed the third green line is removed from the legend. However, it is not a native Matlab structure. Currently this is what I have as code when the GUI is opening: So, I would like to add a legend and give a name to the different curves. Here To create a dynamic legend in MatLab, you can use the "legend" function with the "sprintf" command to include the variable "i" in the legend at each iteration. On my screen it looks like the fol Customizing Legend Position in MATLAB Using the 'Location' Property. 7. Matlab dynamic legend / legend "hold on" like behavior. I tried several things (the example below is just 1 of the many trials), but I can't get it work. To put it better, I would like to "append" a label to my legend every time I update my plot. The vectors v_n are stored in a Adding lines to a legend in a loop can be accomplished with "dynamic legends", as described on undocumentedmatlab. For the labels, the legend uses the text from the DisplayName properties of the data series. g. I need to add legend to them. SCILAB Adding legend in a plot generated by a loop. These arrows are drawn dynamically. This answer is what is inspiring this post: Dynamic Legend (Updates in every recursion). Share. Learn more about legend MATLAB. plot(x, y, 'DisplayName', 'caption'); and then add the legend using the following syntax: How to stop legend from adding 'data1', Learn more about legend . h(1) is the handle of a blue solid line. In below code legend got updated each times thereby leaving me with only the last legend but i want is like 1st iteration plot and its legend and next plot and its legends ;thereby all legends sho How to conveniently add multiple fields to a Matlab struct dynamically? 1. So, in my I want to dynamically assign a legend to a data set with a changing number of vectors (v_1, v_2,,v_n) that I plot against a single vector A. However Instead of crowding my legend with 9 entries, I'd like to depict each color - their meaning (example red - 30-70Hz, blue - 20-50hz etc) and separately the meaning of dotted lines (training set), solid lines (test set) etc. plot(cx , cy, 'r', 'linewidth', 2,'DisplayName','circle'); Now, the legend will have 4 entries because you draw four objects. Learn more about legend, dynamic, script MATLAB Hi to all, I have a simple script that: # loads a *. time and column vs. Find more on Legend in Help Center and File Exchange. 8000), and I would like to reflect the same in the legend. Hot Network Questions I want to dynamically assign a legend to a data set with a changing number of vectors (v_1, v_2,,v_n) that I plot against a single vector A. I wanted to set the legend dynamically. Can we add legend for function "text" to matlab? 0. Sign in to comment. So, I would like to add a legend and give a name to the different curves. In most cases, when you use name-value pairs, you must specify the labels in a cell array, such as legend({'label1','label2'},'FontSize',14). MATLAB scatter plot legend. plot, all lines are drawn on a single Axes object which can be accessed via plt. In the example I'm trying to plot a matrix that's returned from a function. Add a comment | 3 Answers Sorted by: Reset to default 2 I tried to do the same before but I was not successful. These parameters include the font size, font style, color, and position of the legend. 36. This allows you to avoid having to hardcode labels later on and more easily supports dynamic legend creation. See the below example for your reference. How do I add a legend to a boxplot in MATLAB?. Matlab legend for plotting in loop with different colors. How to add legend elements in Matlab in the plot itself. It can be quite elegant and useful. Add legend to graph created iteratively. It currently has a very good running speed, but I cannot figure out how to add a legend to the component plot without slowing down performance. (See Objects with Dynamic Properties. Basically, after each plot, you are able to dynamically update what the legend looks like without having to make one call to legend that has all of them together. Matlab: Calling a legend in a plot which is created with an ''if'' statement. If it has been fewer than 50 milliseconds since the last update, or if the graphics renderer is busy (either with the previous change or because it is initializing), then drawnow skips the new update at that time. Improve this answer MATLAB legend() Function in for-loop- add entry in every loop plotting in loop with different colors. Improve this question. pyplot as plt # Subplots are organized in a Rows x Cols Grid # Tot and Cols are known Tot = number_of_subplots Cols = number_of_columns # Compute Rows required Rows = Tot // Cols # EDIT for correct number of rows: # If one additional row is necessary -> add one: if Tot I have 9 curves on a plot. He has over 50 File Exchange entries, and two of his entries have been highlighted (unit converters and ccc) in Pick of the Week. adding legend that is comes from a variable. Learn more about legend Hi, my task would be to have a legend which is update dynamically as I loop over some data extracted from different files and I add them to a same plot, for instance. and then feeding them into legend alongside the desired strings like so: Dynamic Legend (Updates in every recursion) 1. I create an empty variable and then add cell array elements of strings for each legend entry. Make plot legend with latex equations and other elements. mat" and so For the R2014b+ syntax, the documentation states [lgd,icons,plots,txt] = legend(). For more generic fieldnames, @CitizenInsane's answer using dynamic field references is the only way I know of as well. Ugh, do not use eval like this. Commented Dec 14, 2015 at Add subsequent plot to legend in matlab. That's mean adding new legend if a checkbox is selected on top of existing one but also removing the legend when checkbox is unselected. there's no hold on to add to an existing axes and the X,Y However it will only display the legend for the first plot. mat", "file_002. However, the number of plots are not predetermined and is added according to the user's content. mat" and so Adding variable values into legend. This is the cleaner, easier approach. The available location options include: NorthEast: The default position, ideally for smaller plots without much data in the top right. To do so, you can simply use a Populating a Legend Dynamically. The text string then could become 'n␣␣␣(as spaces as needed to look OK)␣␣␣legend entry text'. And Matlab seems not to have option to manipulate the legend marker, color and linestyle. The one liner looks like this, and would be used within the loop where Slice is defined: So, I would like to add a legend and give a name to the different curves. Today I will expand on that article by explaining the plot legend’s internal graphics hierarchy, how we can Here is the code I used to add the legend: legend([h1 h2],{'label1', 'label2'}); 29 2 2 silver badges 7 7 bronze badges. How to change display format of legend in MATLAB. So, I would like to add a legend and give a name to the different curves. Solution 1: In fact it is possible to have dynamic structures in Matlab environment too. Learn more about dynamic legend, plotting, for loop, nested for loop MATLAB So I am currently working on a code that imports some excel data from any number of files as well as any number of sheets within the excel file. Is there a way to create an Adding Legend in Matlab. You will need to increase the number of rows by 1 and cover drawnow limitrate limits the number of updates to 20 frames per second. Appending a legend entry at the point in code where you add a plot is a convenient way to keep things organized - otherwise you may have blank or doubled legend entires: Populating a Legend Dynamically. Then, when the user clicks on a button, you set the "Visibility" property back to "on". advanced customization of legend markers in matlab. Adding legend in a plot genereted by a loop. legend creates a legend with descriptive labels for each plotted data series. When I plot the three figures in the loop, I want to include legends which state the column name of each variable within the plot. Not that the actual name matters, but moving the position of output icons is a bit confusing. Help Center; Answers; So I went back to the MATLAB documentation and re-visted the carsmall I had a similar problem, to create a legend, but not knowing how many plots I would have. Then create 2nd axes and then move the third line to the 2nd axes. How can I do this? matlab; plot; legend; matlab-figure; Share. MATLAB: Adding a legend to the bottom of a figure without changing figure width or resizing plots. I am trying to extend this answer of the thread Dynamic Legend (Updates in every So, I would like to add a legend and give a name to the different curves. 4. Im getting only the last legend shown. gca(). The third output argument (plots) are handles to the graphics objects in the axes that the legend refers to. " x = 0:360; axis([0 360 -1 1]) Thank you so much for the help! I incorporated this in my code but it is not working completely for me. Learn more about plot, legend, loop, variable and the second line in the plot to be the second eta entry (0. Hi, my task would be to have a legend which is update dynamically as I loop over some data extracted from different files and I add them to a same plot, for instance. I am new to matlab gui and working on my first program. matplotlib scatter plot add legend without loop and without using Use name-value pairs in the legend command. Something in the line of this worked fine for me: legend(app. Learn more about plotting, loop, legend, line MATLAB I'm plotting in a for loop a series of signals and additionally lines to separate segments in the plot. therefore i have to plot the different cell names in the legend. fig to png format but the legend changes its place. Matlab plot legend automation. This property sets the width of the icon in points. This is because if I simply hide the lines, the performance of the program suffers, given that there are so many line options in the real dataset. h(2) is the handle of a red solid line. Can Use name-value pairs in the legend command. Use the Legend object. How can I make legend like this? Thanks! matlab; plot; matlab adding single legend for multiple data. So I am currently working on a code that imports some excel data from any number of files as well as any number of sheets within the excel file. 1. But there is an Hi Paul, thanks for the answer. I would just add that you should move all of your plotting commands except plot outside of the loop. Problem: I want to add a legend to the plot which only contains entries for the Line Dynamic approach. So I use and get this: But I would like to have this, which I got by using the following If you wish to create a legend common for all plots, then you can use the suggestion here. The plotting works fine but the generation of the legend I have found tricky to get right. mat file with a specific name and which is placed in the project directory # plots a figure according to data/variables within the same *. MATLAB: add field to structure within a for loop. MATLAB - Adding a field to the begining of an existing struct. 3. Your question is a little unclear. You can dynamically update the "velocit ies" and "height s A possible way to do it would be first storing in an array h four handles corresponding to four sample lines in the following way:. h(3) is the handle of a dot-dash line. the question is how to write the legend without writting every time it manually ? MATLAB Graphics Formatting and Annotation Labels and Annotations Legend. Is there a way of adding extra legend entries, so that the final plot looks really nice and organised? Matlab dynamic legend / legend "hold on" like behavior (1 answer) Assemble Legend for Many Curves (1 answer) Closed 4 years ago. We can concatenate = between the headerNames and table values (converted using num2str in case there are numeric values), and then use strjoin to generate our label separated by , for each heading. Search Answers Answers. It's use is >> text(x, y, str); where x and y are the coordinates in How to add a legend to a graph with multiple lines. Instead of trying to add a second legend, consider using multiple columns within a single legend (see NumColumns legend property). – Learn more about adding legends I need to display the mean value of the plot in the legend saying mean = 'c4timeavg(1)' m/s. import matplotlib. Going off of OP's code where a bunch of lines were drawn with a single plot() call, we can still add a legend afterwards. plot(s_A_approx, label = q) matplotlib. Since you will be creating 2 axes, hence there will be 2 legends. Adding Legend in Matlab. The above callback function is used to draw arrows in a plot. Find the treasures in MATLAB Central and discover how the community can help you! Start Hunting! Use name-value pairs in the legend command. Even with the added axis, my second legend eliminates the first. Customized Legend in Matlab. I am not aware of the existance of "markermap". (See Set and Get Methods for Dynamic Properties. I thought of the following: I could make the default legend line or marker invisible (can be done with icons, the legend output in the question). Even if I turn auto-update off and only create the legend for the first set of points plotted, it somehow still finds a way to slow down my program significantly as it continues to run. Tags plot; hold on; Hi, my task would be to have a legend which is update dynamically as I loop over some data extracted from different files and I add them to a same plot, for instance. 125k 25 25 gold badges 247 247 silver badges How to add legend inside Python's Bokeh circle plot. there's no hold on to add to an existing axes and the X,Y If you look at the legend, you'll notice that after we added the ConstantRegion and ConstantLine, there's a lot of padding surrounding the scatter icon. This approach requires you to update the plotted One way to accomplish this is to create the GUI objects at the start, but set their "Visibility" property to "off". However there is a trick to achieve what you want. matlab plot legend variable. To put it When you create a plot, you can specify the legend labels by setting the “DisplayName” property as name-value pair. Each table has ten columns (in addition, each column includes column names). The second output (icons), as you say here, are handles to the stuff used to draw the legend itself. RuiQi on 13 Jul 2017. You can return Populating a Legend Dynamically. Load 7 more related questions Show fewer related questions Sorted by: Reset to default Know someone who can answer? Share a link to this question via email, Twitter, or Facebook. I have ~10 datasets that I need to plot , but only when activated by a checkbox selection where two plots will be generated in axes1 and axes2. Dynamic structure referencing has its own dangers, but it's clearer than dynamic variable creation. This could change if MATLAB would create comma-separated lists from dynamic fields with cell string arguments, but that is but a dream of mine. lines. show() python; matplotlib; Hi Paul, thanks for the answer. Add legend to a group of lines. You could fix the problem just by define upfront the different markers So, I would like to add a legend and give a name to the different curves. png from is attached to the post. Add subsequent plot to legend in matlab. Firstly, plot all line on the same axes, then run legend. mat" and so I have made a graph in Matlab which generates points and plots a red cross if the point is inside a specified box, and a blue circle if it is outside. I dont know how to add a label for each graph to form a legend. This can be confirmed by comparing the figure children to the axes and legend handles. fig file that I am trying to save . 2. com. Matlab: Need to create a legend dynamically for plotted points. plotUIaxes, 'first_label','second_label') assuming the name of your 2D axes component is app. and it became instead (displayName for each graph + legend('-DynamicLegend')) As this became a standard (as in no Dynamic Legend is required), it is sufficient to add show legend This is a tricky problem since the legend are somehow connected to the axes. the question is how to write the legend without writting every time it manually ? clc;clear all ;close all The built-in Matlab legend function has a very useful semi-documented feature for automatic dynamic update, which is explained here. I am trying to save figure from . MATLAB Answers. 0. I've decided to dynamically add and remove line glyphs from the plot as they are selected in the MultiSelect. His entries are well-written, and like this one, many of his entries have published example files. This is what I'm trying to get to work: Add flexible legend in MATLAB. Which version of Matlab are you using? Running the code on mine (2014b) gives me what you want - no clickableLegend is a wrapper around the LEGEND function that provides the added functionality to turn on and off (hide or show) a graphics object (line or patch) by clicking on its text label in the legend. pylab. Or use a map container – sco1. My question now is : I want the legend to be automatically updated regarding the set of data I have selected using the checkbox. for q in range(1,10): matplotlib. Learn more about boxplot, legend, boxchart Statistics and Machine Learning Toolbox. Set it to manual to prevent this: >> set(gca, 'YLimMode', 'manual'); In order to have the limits update automatically to appropriate values when the data on the plot is updated you could listen for updates to the line using an event listener. The dynamic legend is another thing, it is mainly to have "DisplayName" to be used, in each graph, instead of using a global legend({'a','b'}). Just adding a legend at the end of the plotting only shows an entry corresponding to the last point plotted. I perform the battery tests for two different temperatures-->i at each different temperatures, there are different cells (whose names ans details are stored in folder called cell list) under test, that gives j. Learn more about plots, legend, multiple legends Hello, i am looping over different valuesthat effect the plot and i can get a legend that shows how these values relate to the lines shown in the plot. So, in my example I should have a legend with labels "file_001. To create a dynamic legend in MatLab, you can use the "legend" function with the "sprintf" command to include the variable "i" in the legend at each iteration. I want to do this by adding a second legend (in an own "legend-window") to the figure As far as I know, you can only have one legend-window for one set of axes in MATLAB, so the idea is: add a second (exatly equal) set of axes to the figure Suppose you know total subplots and total columns you want to use:. I don't understand what you are doing creating the full legend within the With the data I want to plot the data taken from the files, I want a legend to be dynamically populated with the information as it is going through the loop as it is running. This data is a lot and the names will have to be added in a looped manner. If the DisplayName property is empty, then the legend uses a label of the form 'dataN'. legend( arrayfun( @num2str, alpha, Find the treasures in MATLAB Central and discover how the community can help you! Start Hunting! Create a custom legend . mat" and so on (according to 'h' range). Chad is no stranger to MATLAB Central. Just create the legend for the last one and position it at SouthOutside. How to By default, dynamic properties have their NonCopyable attribute set to true. A drawback of the above is that the legend will cease to be aligned if the figure is resized. I have a loop which processes three tables. As such, try something like Edit: Here is a flexible way to auto-generate the "filter" label from the Slice. But that doesn't solve my problem, because the undesired red line How to dynamically allocate labels to a legend?. Font type from Matlab to LateX. 3928)? How can I do this dynamically so that it is automated if I change the values in eta or if I make it have more numbers? 2 Comments MATLAB Graphics Formatting and Annotation Labels The y-axis limits will rescale automatically if the YLimMode of the axis is set to auto. ) Add property set and get access methods. I want to add a Legend for each of the signal but when I add the legend it adds the lines too @zelanix - thanks for the link and suggestions. Plotting a variable in a Legend - Matlab. The answers below are correct to suggest moving the legend outside of your for loop. Learn more about legend, plot, plotting, for loop, data I want to dynamically assign a legend to a data set with a changing number of vectors (v_1, v_2,,v_n) that I plot against a single vector A. Diff conditions: how to clear dynamic legends at the end of each iteration; how to remove fitted linear lines at the end of each iteration. I am generating the plots in a for loop and want to add the legends dynamically. The above code will have only one legend. Adding a legend manually for a plot generated by Learn more about legend, plot MATLAB Any ideas on how to create a dynamically changing legend? The code is included below: AOI_unique=unique(AOI); %for each of those unique AOI's, plot the row vs. The legend automatically updates when you add or delete data series from the axes. [~,~,~,names] = legend; legend([names {'my new line name'}]); Another way is to track the names of lines using their DisplayName property, and then rebuild the legend based on the current state of the plot when you add something new. I have data that I am plotting using a for loop. DisplayName is what legend() uses to auto-generate the line names when you call the simple "legend show" form. The idea is to replace the legend command with: legend('-DynamicLegend'); how to add legend automatically : for exmaple this is my code . . Your Answer Reminder: Answers generated by I need an additional text in the legend that is not related with graphical data together with the legend captions. I've been thinking how I could update in Matlab the legend of my plots as the for goes on, Dynamic Legend (Updates in every recursion) 1. ) Listen for dynamic property events. The limit on the number and names of properties is not nearly as significant as strong typing, which matlab doesn't have. This is a rather undocumented feature but it does work very well. The name in the legend should be simply the name of the *. I want to dynamically assign a legend to a data set with a changing number of vectors (v_1, v_2,,v_n) that I plot against a single vector A. Its usage is the same as the LEGEND function in MATLAB. Then, use lgd with dot notation to set properties, such as lgd. Add subsequent plot to Dire warnings about dynamic variable creation have been added to the answer. The gscatter function does contain the ability to add colors (it's in the part you have as '' before the marker type). Learn more about dynamic legend, plotting, for loop, nested for loop MATLAB for loop, nested for loop MATLAB. set the DisplayName property of each item you want to appear in the legend then use the final legend call simply to tell MATLAB "Show the legend now. Also, these values may change dynamically for other cases (the number of lines may vary each time). Hot Network Questions Why are there no no-attribution licenses other than "public domain"? What are the maximum bonuses of each type possible? Is it I have the following string: Now I want to use this string to produce a legend to my figure. I want all 9 off them to be displayed. Recently, I had to write a graph traversal script in Matlab that required a dynamic stack. x = linspace(0,pi How do I dynamically add markerfacecolors to Learn more about gscatter, markerfacecolor MATLAB I've discovered that specific verbiage can in fact be added to the legend. I looked at answers using the "DisplayName" property while plotting, but I didn't want to rewrite all of my plotting, and in any case ewasn't sure how to use it with plotyy (probably using hax = plot / semilogy construct). I met with an issue where when I want to add legends to numerous graphs with the legend naming like : "36", "42" as they represent the velocity. h(4) is the handle of a dot-cross line. You can return the Legend object as an output argument from the legend function, such as lgd = legend. MATLAB provides the 'Location' property to allow users to specify predefined positions for legends, making customization straightforward and effective. However, the first thing I thought of when reading it was the text function in Matlab. I don't think there is a lot of robustness to begin with. Follow 18 views (last 30 days) Show older comments. This can be done by using colors = hsv(i). Plotting, marking and legend in a loop. Another possibility is to use the dynamic legend (not so-well documented) feature of MATLAB. I created a boxplot and would like to add a legend to it, but when I call legend I get the following warning message and there is no legend in the plot figure: Warning: Plot empty. Sign in to answer this question. It's possible to test for the existence of fields before access, and it's a very handy way to create a string/value storage system. plotUIaxes and you want to label two curves. Many of you may know that the Let's say I'm plotting a range of voltage values (both experimental and theoretical) and I want to dynamically change the legend of the plot each time from a string such as ("experimental from range vector(a)-vector(b)") where vector just refers to some numeric array. Plotting in MATLAB and legend. What do you lose by dynamically adding a field -- this won't break any legend dynamically updated. Set the "DisplayName" property to a character You can pass labels to the legend function in a cell array so you can create that dynamically as e. fcvzqbg iydqx gata spav pburu admb zumakp eovaxo ydow zplvatd