Subplot in matlab12/5/2023 ![]() ![]() Instead, I had to make the axes children of the new figure. Object figure can not be a child of parent ![]() For example hNew = copyobj(fig(1),hFigure) gave the error Error using copyobj It seemed that a figure couldn't be made the child of another figure. The code from gnovice didn't work for me. You could avoid the need to create and then delete subplots by specifying the positions yourself. Set(hNew,'Position',newPos) %# Modify its positionĪlso note that SUBPLOT is only used here to generate a position for the tiling of the axes. If you want the axes object to appear in both figures, you can instead use the function COPYOBJ like so: hNew = copyobj(fig(1),hFigure) %# Copy fig(1) to hFigure, making a new handle The above will actually move the axes from the old figure to the new figure. Since you call geobasemap and geolimits before geoscatter, they attemp to operate on the cartesian axes, which is not allowed. HTemp = subplot(2,1,2,'Parent',hFigure) %# Make a new temporary subplot subplot creates a cartesian axes in the current position. Set(fig(1),'Parent',hFigure,'Position',newPos) %# Move axes to the new figure NewPos = get(hTemp,'Position') %# Get its position HTemp = subplot(2,1,1,'Parent',hFigure) %# Create a temporary subplot However, to answer the question you asked, here's a way to accomplish this given that you are outputting the axes handles (not the figure handles) in the vector fig ( note: this is basically the same solution as the one given in the other question, but since you mention having trouble adapting it I thought I'd reformat it to better fit your specific situation): hFigure = figure() %# Create a new figure no additional arguments specified) would be to create its own figure and place the plot there. The default behavior of myFunkyFigure (i.e. MyFunkyFigure(dataSet2,hSub2) %# Add a funky plot to the second subplot axes HSub2 = subplot(2,1,2) %# Create a second subplot ![]() MyFunkyFigure(dataSet1,hSub1) %# Add a funky plot to the subplot axes Then you would use it like so: hSub1 = subplot(2,1,1) %# Create a subplot Plot(piektijden_start(startnummer(1:end-1),1),slagfrequentie_start,'.Obviously, we don't know how "funky" your figures are, but it should be noted in such a case that the cleanest solution would be to modify the function myFunkyFigure such that it accepts additional optional arguments, specifically the handle of an axes in which to place the plot it creates. Subplot(2,i,i+i),plot(piektijden_start(startnummer(1:end-1),1),slagfrequentie_start) Subplot(2,i,i),plot(piektijden_start(startnummer(1:end-1),1),slagtijd_start) Slagfrequentie_start= (60./slagtijd_start) Slagtijd_start= diff(piektijden_start(startnummer)) Startnummer = find(piektijden_start(:,2) = i) I've posted my code and resulting figure below, I've tried different things with 'hold on' etc. In this case i = 3 and the figure only displays the two latest subplots. Plotting on the right postions works, except that matlab erases the previous subplots (previous values of i). So when the maximum value of i = 3, we have a subplot matrix of 2x3 axes, I'd like to plot two variables in two subplots below each other for every value of i : slagtijd_start & slagfrequentie_start The total number of subplots is dependent on the maximal value in a matrix: maximal value of 'i'. I'm trying to plot several subplots in a single figure. ![]()
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |