From help-octave-request at bevo dot che dot wisc dot edu Mon Mar 22 09:15:15 2004 Subject: Re: partial plot From: Miquel Cabanas To: "Pascal A. Dupuis" Cc: Octave_post Date: Mon, 22 Mar 2004 16:10:35 +0100 ok, that requieres a bit of octave code to handle the situation On Fri, Mar 19, 2004 at 02:11:08PM -0600, Pascal A. Dupuis wrote: > > In the case of NaN, the value is ignored, and lines are interpolated > around the missing point. What I would like is to have the line stop > before the missing value, to emphasize the fact that nothing is available. > i think the code below will work, otherwise feel free to modify and/or improve it to fit your needs. So far I have tested having NaN at one or both ends, having consecutive NaN, and nothing crashed, but in some cases x_to_plot and y_to_plot were equal to "[](0x0)", though nothing wrong happened. y = [10, -20, NaN, -40, 50, NaN, 70, -80]; x = 1:1:length(y); ## create a vector that will hold the discontinuities, ## i.e. NaN's indices discontin = find(isnan(y)) if !isnan(y(1)) ## first point is a number, pretend there's a NaN at #0 discontin = [0, discontin] endif if !isnan(y(length(y))) ## last point is a number, pretend there's a NaN past the end discontin = [discontin,length(y)+1] endif figure(); hold on; for i=1:length(discontin)-1 ## create subvector to plot x_to_plot = x(discontin(i)+1:discontin(i+1)-1) y_to_plot = y(discontin(i)+1:discontin(i+1)-1) ## plot data plot(x_to_plot, y_to_plot, 'o-') endfor Briefly, in the above case, discontin = [3 6] in a first instance, and then discontin = [0 3 6 9] after adding the fake NaN that limit the edges of y-vector. The plotted subvectors are y(1,2), y(4,5) and y(7,8). Hope this helps, Miquel -- Miquel E Cabanas ------------------------------------------------------ SeRMN, Universitat Autonoma de Barcelona (Miquel dot Cabanas at uab dot es) ------------------------------------------o-oo--ooo---ooo--oo-o-------- ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------