That way, at the second iteration the plot from the 2nd iteration will be plotted, the plot from the 1st will be deleted and after these operations I get it to display the plot (again drawnow). I delete h_old and overwrite it with the new plots I created. (2, better in my view) make your own legend object (it's only a special axes object after all) which you can then move/copy/modify freely within your figures. Second Plot (in the called function) h(1)=plot(points,modeldata1,'r-','DisplayName','Model Data, L= 0.1 m') 2 hacky options: (1) add empty lineserie (or any empty graphic object) in the axes so that there are enough to populate the legend. I chose 0,250 because it's in the range of the data (otherwise it messes up the axis) Legend('-DynamicLegend','Location','Best')ĭrawnow forces the plot to be drawn right away, and h_old is just a "placeholder" that I make use of later on. Plot(points,expdata3,'go','DisplayName','Experimental, L= 0.3 m') You can give your plot a title (with the title command), x -axis label (with the xlabel command), y -axis label (with the ylabel command), and put text on the actual plot. example legend (label1.,labelN) sets the legend labels. If no axes exist, then legend creates a Cartesian axes. If the current axes is empty, then the legend is empty. This command creates a legend in the current axes, which is returned by the gca command. Plot(points,expdata2,'bo','DisplayName','Experimental, L= 0.2 m') Adding text and legend Another thing that may be important for your plots is labeling. The legend automatically updates when you add or delete data series from the axes. I was able to do it with a combination of solutions from different questions.Ĭlose all will ensure your plot starts anew every timeįirst plot (in my main) plot(points,expdata1,'ro','DisplayName','Experimental, L= 0.1 m') hold on I had a similar issue: I plotted three sets of experimental data first, then got into my parameter estimation to simulate the function and wanted to plot the model data every time, holding on to the experimental data but deleting the model data from the previous run.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |