plot_labeled_snn.m
来自「神经网络的工具箱, 神经网络的工具箱,」· M 代码 · 共 109 行
M
109 行
function plot_labeled_snn(x, y, labels, varargin);%PLOT_LABELED_SNN Labeled linear plot.%% Syntax%% plot_labeled_snn(x, y, labels);% plot_labeled_snn(x, y, labels, s);%% x - double array.% y - double array.% labels - cell array of strings.% s - character string.%% Description%% PLOT_LABELED_SNN(X, Y, LABELS) plots vector Y versus vector X and% labels each point/line-between-points with LABELS.%% Various line types, plot symbols and colors may be obtained with % PLOT_LABELED_SNN(X, Y, LABELS, S) where S is a character string as% in the default PLOT command.%% Examples%% plot_labeled_snn([1 2 3], [4 5 6], {'first', 'second'}, '+-');% plot_labeled_snn([1 2 3], [4 5 6], {'first', 'second', 'third'});%% See also%% PLOT%no_x = prod(size(x));no_labels = prod(size(labels)); if (no_x == no_labels) plot(x, y, varargin{:}); draw_labels(x, y, labels); elseif (no_x == (no_labels + 1)) plot(x, y, varargin{:}); x_l = x([1:no_x-1]) + (x([2:no_x]) - x([1:no_x-1]))/2; y_l = y([1:no_x-1]) + (y([2:no_x]) - y([1:no_x-1]))/2; draw_labels(x_l, y_l, labels); else error('Number of elements for first and third argument do not match');end%--------------------------------------------------------------------------function draw_labels(x, y, labels)for i = 1:prod(size(x)) v = axis; dx = (v(2)-v(1))/10; dy = (v(4)-v(3))/10; draw_arrow(x(i), y(i), 0, dx, dy, 'r', 1); set(text,'Position',[x(i),y(i)-1.5*dy],... 'HorizontalAlignment','center',... 'VerticalAlignment','top',... 'String',labels{i},... 'FontSize',12);endreturn;%--------------------------------------------------------------------------function draw_arrow(x0,y0,phi,sx,sy,ss,filled);% draws an arrow in the current figure.if nargin < 7, filled = 0;endif nargin < 6, ss = 'y-';endif nargin < 5, v = axis; sy = (v(4)-v(3))/10;endif nargin < 4, v = axis; sx = (v(2)-v(1))/10;endif nargin < 3, phi = 0;endx = [0,-1/3,-1/12,-1/12,1/12,1/12,1/3,0];y = -[1/4,3/4,8/12,1,1,8/12,3/4,1/4];phi = phi*pi/180;xn = cos(phi)*x + sin(phi)*y;yn = -sin(phi)*x + cos(phi)*y;xo = x0 + sx*xn;yo = y0 + sy*yn;dummy = ishold;hold onif filled, fill(xo,yo,ss);else plot(xo,yo,ss);endif ~dummy, hold offend
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?