For a beginning Matlab plotting project instructions are to use several commands. I used everything except for "subplot" and "hold". Can anyone tell me how I could work it into the following code?:
Show older comments
%Define parameters of r and functions
r=0:.1:1;
Ea=-1.436./r;
Er=(5.86.*10.^-6)./(r.^9);
En=Ea+Er;
%plot functions with given r values
plot(r,Ea,'--',r,Er,'-',r,En,':')
%set axis according to the best fit for pertinent information
axis ([0 1 -15 15]);
%Display equations on graph, modified according to in-class example
text(.20,-10,'Ea=$\displaystyle\frac{-1.436}{r}$','interpreter','LaTeX') text(.7,3,'Er=$\displaystyle\frac{5.86*10.^-6}{r.^9}$','interpreter','latex') text(.05,0,'En=$En+Ea$,','interpreter','latex')
% Create xlabel
xlabel({'Interatomic Separation,r, nm'});
% Create ylabel
ylabel({'Potential Energy, E'});
% Create title
title({'K.^+ -C.^- Ion Pair, Attractive, Repulsive, and Net Energies'});
% Create textbox
annotation('textbox',... [0.73 0.78 0.17 0.13],... 'String',{'Name','Net id:00000','Feb. 4, 2013'},... 'FitBoxToText','off');
%Create legend, specify location
hleg1=legend('Attractive Force (Ea)','Repulsive Force (Er)','Net Energy (En)'); set(hleg1,'location','SouthEast');
5 Comments
Amit
on 5 Feb 2014
what you're trying to plot with subplot? I mean which variables with what and how many subplots?
cassie
on 5 Feb 2014
Amit
on 5 Feb 2014
I plotted the code you have written here. You have done a very nice job in doing that, Kudos. If I was you, i'd use this plot as it is.
Subplot will shrink the axes. However, if you really need to use the subplot, that I (or anyone else) can explain on how to use it. Is that your question?
Image Analyst
on 5 Feb 2014
Then split it into two calls to plot() like Amit showed you. It will plot in two separate graphs/charts, instead of both on one graph.
Accepted Answer
More Answers (1)
Image Analyst
on 5 Feb 2014
0 votes
subplot() just tells it WHERE to plot. plot() does the actual plotting. Since you have only a single plot, I don't see any reason to use subplot().
hold on tells it not to blow away any existing plot when you plot another one - it will keep both. Since you are not calling plot() more than once, you will not need to use hold.
Categories
Find more on Subplots 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!