📄 monocline.m
字号:
function y = monocline(n, center, width, left, right)% monocline -- Monocline-like distribution function.% monocline(n, center, width, left, right) returns n points% on the range [0...1], distributed with the given transition% center, width (st.dev.), left-side density, and right-side% density (both relative). The distribution is generated by% "erf()". Defaults: center = 0.5, width = 0.1, left = 1,% right = 2.% monocline(x, ...) assumes that x is "linspace(0, 1, n)".% monocline('demo') demonstrates itself for n = 51. % Copyright (C) 1999 Dr. Charles R. Denham, ZYDECO.% All Rights Reserved.% Disclosure without explicit written consent from the% copyright owner does not constitute publication. % Version of 01-Sep-1999 10:05:23.% Updated 01-Sep-1999 16:59:22.if nargin < 1, help(mfilename), n = 'demo'; end% Demonstration.if isequal(n, 'demo') n = 51; center = 0.5; width = 0.1; left = 1; right = 2; result = feval(mfilename, n, center, width, left, right); x = linspace(0, 1, n); plot(x, result, '-', [0*x; 0*x+1], [result; result], 'g-') s = [mfilename '(' int2str(n) ', ' num2str(center), ', ' ... num2str(width) ', ' num2str(left) ', ' num2str(right) ')']; title(s) xlabel x ylabel y grid on eval('zoomsafe', '') figure(gcf) if nargout > 0, y = result; end returnend% Missing arguments.if nargin < 2, center = 0.5; endif nargin < 3, width = 0.1; endif nargin < 4, left = 1; endif nargin < 5, right = 2; end% String arguments.if ischar(n), n = eval(n); endif ischar(center), center = eval(center); endif ischar(width), width = eval(width); endif ischar(left), left = eval(left); endif ischar(right), right = eval(right); endif length(n) > 1, n = length(n); end% ERF and TANH are very similar, differing% by about 20% in the independent variable:% tanh(x) =~ erf(0.8*x).fcn = 'tanh';fcn = 'erf';x = linspace(1/n, 1-1/n, n-1); % Centered x-values.y = feval(fcn, (x-center)/width); % ERF-like.y = (y + 1) / 2; % ERF on a pedestal.% Shift and scale.y = left + y * (right-left); % Unnormalized density.y = cumsum(y); % Cumulative unnormalized density.y = y / max(y); % Normalize.y = [0 y]; % Prepend zero starting point.y(end) = 1; % Exactly one at end.% Reverse interpolate.x = linspace(0, 1, n);y = interp1(y, x, x, 'linear');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -