Plots combining to produce one single plot
2 views (last 30 days)
Show older comments
Commented: Daniel Underwood on 16 Feb 2020
I am completing a MATLAB course as part of my PhD studies but I am having an issue that is leaving me completely flumaxed. Early on in the module I used the following code to produce a plot, which all worked fine.
v = @(S,K,Vmax) Vmax*S/(K + S);
v1 = @(S) v(S,0.1,10);
v2 = @(S) v(S,1,10);
v3 = @(S) v(S,10,10);
limits = [0 10];
axis([0 10 0 10])
Later on I used this next bit of code to produce a different plot
%1) Plot a rate curve with a Eo value of 4, a k2 value of 0.03, a k-1
%value of 0.003, and a k1 value of 0.01.
k2 = 0.03;
Eo = 4;
k1 = 0.01;
kminus1 = 0.003;
Vmax = k2*Eo
Km = (kminus1+k2)/k1
v = @(S) Vmax*S/(Km+S);
limits = [0 100];
What is happening is that the two plots are combining, even if I seperate them out as different sections and run the latter as it's own seperate thing. However, I know my code works to produce the plot I want as when I copy it into the command window or a seperate live file it works fine. So clearly these two are interacting but I don't know how. I tried changing the v in the second set of code to a q and plot fplot(q,limits) but that made no difference.
Help me wider community, you are my only hope.
Joseph Cheng on 16 Feb 2020
Edited: Joseph Cheng on 16 Feb 2020
What i see is that you have a hold on and you didn't turn it off or designate a new plotting window/figure. Such athat depending on the order of running these sections it'll probably plot within the same window. Good practice if you want a new plot is to use the function figure() to generate a new plotting window and work with axes and figure handles. the function figure can take in a figure handle or a number to designate the window number. figure(1) or figure(100) will open up a new figure with that window number assigned it.
below is a snippet of code to show what is happening as well as how to assign and designate figure and axes handles to designate where plots go.
%here showing the stacking of plots due to the "hold on"
figure(1) ; %open new figure
%%doing other stuff here
legend('first plot','second plot')
%forcing plots into new figures, and pointing the plots into which
%figure/axes to plot into
hfig2 = figure(2); %generate handle for figure(2)
hax2 = axes(hfig2); %assign handle for axes in figure(2)
hfig3 = figure(3);
hax3 = axes(hfig3);
%put plot specifically into figure(2)
%put plot specifically into figure(3)
More Answers (0)
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!