http://www.mathworks.com/matlabcentral/newsreader/view_thread/276236
MATLAB Central Newsreader  Problems with plotting lines and curves
Feed for thread: Problems with plotting lines and curves
enus
©19942014 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Thu, 11 Mar 2010 21:30:25 +0000
Problems with plotting lines and curves
http://www.mathworks.com/matlabcentral/newsreader/view_thread/276236#725649
Andrew Cross
Hi,<br>
<br>
I'm fairly new to Matlab and am having some problems with plotting functions.<br>
I've got two functions that I want to plot. One is a line, the other is a negative exponential curve. Both functions are calculated with depth simultaneously, but I only want to display one of the functions at each given depth (i.e. when the line function has a value less than that of the curve, I want it to plot the line, but when the curve becomes less than the line, I want to only plot the curve).<br>
<br>
If I do this within the for loop, it only plots the points at which depth is calculated (h = 0:0.1:40)  is there any way to join these points to form a solid line? The code is:<br>
<br>
if (var2(:,n) < var3(:,n))<br>
plot(var2(n),h(n),'linewidth',1);<br>
legend('Straight line');<br>
else <br>
plot(var3(n),h(n),'r','linewidth',1);<br>
legend('Curve');<br>
end <br>
<br>
Otherwise, if I place the plot function outside the for loop, the 'if' function doesn't work and only plots whichever function is least at the maximum depth.<br>
<br>
Any help really would be very much appreciated!<br>
<br>
Cheers,<br>
<br>
Andrew

Fri, 12 Mar 2010 00:51:04 +0000
Re: Problems with plotting lines and curves
http://www.mathworks.com/matlabcentral/newsreader/view_thread/276236#725684
Sadik
Hi Andrew,<br>
<br>
Why not collect the line and the curve in two separate vectors? You should also collect the corresponding depth info so that you will say:<br>
<br>
plot(hLine,linePoints)<br>
hold on<br>
plot(hCurve,curvePoints,'r')<br>
<br>
or something like that.<br>
<br>
Best.<br>
<br>
<br>
"Andrew Cross" <butross@hotmail.com> wrote in message <hnbndh$2uk$1@fred.mathworks.com>...<br>
> Hi,<br>
> <br>
> I'm fairly new to Matlab and am having some problems with plotting functions.<br>
> I've got two functions that I want to plot. One is a line, the other is a negative exponential curve. Both functions are calculated with depth simultaneously, but I only want to display one of the functions at each given depth (i.e. when the line function has a value less than that of the curve, I want it to plot the line, but when the curve becomes less than the line, I want to only plot the curve).<br>
> <br>
> If I do this within the for loop, it only plots the points at which depth is calculated (h = 0:0.1:40)  is there any way to join these points to form a solid line? The code is:<br>
> <br>
> if (var2(:,n) < var3(:,n))<br>
> plot(var2(n),h(n),'linewidth',1);<br>
> legend('Straight line');<br>
> else <br>
> plot(var3(n),h(n),'r','linewidth',1);<br>
> legend('Curve');<br>
> end <br>
> <br>
> Otherwise, if I place the plot function outside the for loop, the 'if' function doesn't work and only plots whichever function is least at the maximum depth.<br>
> <br>
> Any help really would be very much appreciated!<br>
> <br>
> Cheers,<br>
> <br>
> Andrew