From: "Sadik " <>
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$>
References: <hnbndh$2uk$>
Reply-To: "Sadik " <>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1268355064 26850 (12 Mar 2010 00:51:04 GMT)
NNTP-Posting-Date: Fri, 12 Mar 2010 00:51:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1666517
Xref: 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:

hold on

or something like that.


"Andrew Cross" <> wrote in message <hnbndh$2uk$>...
> 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