source: MML/trunk/machine/SOLEIL/common/toolbox/ezyfit/ezyfit/semilogypn.m @ 4

Last change on this file since 4 was 4, checked in by zhangj, 10 years ago

Initial import--MML version from SOLEIL@2013

File size: 3.1 KB
Line 
1function [hp, hn] = semilogypn(x,y, specpos, specneg, varargin)
2%SEMILOGYPN Semilogarithmic  plot for positive and negative data.
3%   SEMILOGYPN(...) is the same as SEMILOGY(...), except that the Y data
4%   may have positive and negative values. This is useful to detect
5%   unexpected negative values in the Y data (causing repeated 'Negative
6%   data ignored' warnings), or to visualize the magnitude of an
7%   oscillating signal in log scale.
8%
9%   SEMILOGYPN(X,Y) plots X versus Y as logarithmic scales, where Y may
10%   have positive and negative values. By default, negative values are
11%   ploted with dashed lines and positive values with full lines. If X is
12%   not specified, Y is plotted versus its index.
13%
14%   SEMILOGYPN(X,Y,LineSpecPos,LineSpecNeg) specifies LineSpecPos and
15%   LineSpecNeg for the line types, marker symbols and colors for the
16%   positive and negative values of Y. For instance,
17%   SEMILOGYPN(X,Y,'ro-','b*') plots the positive Y with red line and 'o'
18%   markers and the negative Y with blue stars '*'.
19%   
20%   SEMILOGYPN(X,Y,LineSpecPos,LineSpecNeg,'PropertyName',PropertyValue,...)
21%   sets property values for all lineseries graphics objects created by
22%   SEMILOGYPN. See the line reference page for more information.
23%
24%   [HP, HN] = SEMILOGYPN(...) returns the handles to the two lineseries
25%   graphics objects.
26%
27%   Example:
28%      x = linspace(1,10,200);
29%      y = sin(x*2)./x;
30%      semilogypn(x,y,'r.','bo');
31%      axis([1 10 1e-2 1]);
32%
33%      semilogypn(x,y,'b-','r:','LineWidth',2);
34%
35%      [hp, hn] = semilogypn(x,y,'k');
36%      set(hp, 'LineWidth', 1);
37%      set(hn, 'LineWidth', 2);
38%
39%   See also SEMILOGY, LOGLOG, LOGLOGPN.
40
41%   F. Moisy, moisy_at_fast.u-psud.fr
42%   Revision: 1.01,  Date: 2007/04/12
43%   This function is part of the EzyFit Toolbox
44
45% History:
46% 2007/04/10: v1.00, first version.
47% 2007/04/12: v1.01, do not draw lines between ranges of Y
48%                    separated by ranges of opposite sign.
49
50error(nargchk(1,inf,nargin));
51
52if nargin<2
53    y = x;
54    x = 1:length(y);
55end
56
57if nargin<3        % default LineSpecs:
58    specpos = 'b-';
59    specneg = 'b--';
60elseif nargin<4    % LineSpec for Y<0 if the LineSpec for Y>0 is specified
61    if findstr(specpos,'--')
62        specneg=strrep(specpos,'--','-');
63    else
64        specneg=specpos;
65        specneg=strrep(specneg,'-.','');
66        specneg=strrep(specneg,':','');
67        specneg=strrep(specneg,'-','');
68        specneg=[specneg '--'];
69    end
70end
71
72indpos = find(y>0);
73indneg = find(y<0);
74
75ypos = y;
76ypos(indneg) = 0;
77
78yneg = y;
79yneg(indpos) = 0;
80
81if isempty(indneg) && ~isempty(indpos)
82    hp = semilogy(x, ypos, specpos, varargin{:});
83    hn = [];
84elseif ~isempty(indneg) && isempty(indpos)
85    hp = [];
86    hn = semilogy(x, -yneg, specneg, varargin{:});
87else
88    statehold = ishold;   % figure was 'held on' before?
89    hp = semilogy(x, ypos, specpos, varargin{:});
90    hold on
91    hn = semilogy(x, -yneg, specneg, varargin{:});
92    if statehold==false
93        hold off
94    end
95end
96
97if ~nargout
98    clear hp hn
99end
Note: See TracBrowser for help on using the repository browser.