Path: news.mathworks.com!not-for-mail
From: "Sadik " <sadik.hava@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Problems with plotting lines and curves
Date: Fri, 12 Mar 2010 00:51:04 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 36
Message-ID: <hnc35o$q72$1@fred.mathworks.com>
References: <hnbndh$2uk$1@fred.mathworks.com>
Reply-To: "Sadik " <sadik.hava@gmail.com>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1268355064 26850 172.30.248.38 (12 Mar 2010 00:51:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 12 Mar 2010 00:51:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1666517
Xref: news.mathworks.com comp.soft-sys.matlab:616121

Hi Andrew,

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:

plot(hLine,linePoints)
hold on
plot(hCurve,curvePoints,'r')

or something like that.

Best.


"Andrew Cross" <butross@hotmail.com> wrote in message <hnbndh$2uk$1@fred.mathworks.com>...
> Hi,
> 
> I'm fairly new to Matlab and am having some problems with plotting functions.
> 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).
> 
> 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:
> 
>    if (var2(:,n) < var3(:,n))
>        plot(var2(n),h(n),'linewidth',1);
>        legend('Straight line');
>    else       
>        plot(var3(n),h(n),'r','linewidth',1);
>         legend('Curve');
>    end 
> 
> 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.
> 
> Any help really would be very much appreciated!
> 
> Cheers,
> 
> Andrew