plot_data.m~

来自「一个用EM算法的源程序」· M~ 代码 · 共 112 行

M~
112
字号
% plot_data(data, sampleLabels)%% The main function for plotting data generated by the GPCA algorithm.%% Can handle two or three dimensional data.%% Can also display a set of normal vectors on the same graph.  Not all% normal vectors need to be computed; the number to be displayed must be% specified.  Normal vectors will be rendered in order they are passed.%function pl = plot_data(data, sampleLabels)% Hold while drawing a bunch of elements to the current figure.originalHoldState = ishold;hold on;if ~exist('sampleLabels','var'),    sampleLabels = ones(1,size(data,2));endgroupCount = max(sampleLabels);sampleCount = size(data,2);markers = '.ox+*svp^h<>'; markerCount = length(markers); markerIndex = 1;colors = 'rbkmgcy'; colorCount = length(colors); colorIndex = 1;if size(data,1) == 2    % Plot outliers    groupDataIndices = samplelabels==0    if ~isempty(groupDataIndices)            end        for groupIndex = 1:groupCount,        groupDataIndices = sampleLabels == groupIndex;                pl = plot(data(1, groupDataIndices),data(2,groupDataIndices), [markers(markerIndex) colors(colorIndex)]);        %       set(pl,'MarkerSize', 5);        % Set the plot to the default 2D view.        view(2);                        % Advance to the next color, and marker if all of the colors have        % been used.        colorIndex = colorIndex+1;         if (colorIndex > colorCount),            colorIndex = 1;             markerIndex + 1;            if (markerIndex > markerCount),                markerIndex = 1;            end;        end;    end        xlabel('axis 1')    ylabel('axis 2')    elseif size(data,1) == 3    % Plot outliers    groupDataIndices = samplelabels==0    if ~isempty(groupDataIndices)    end        for groupIndex = 1:groupCount,        groupDataIndices = sampleLabels == groupIndex;                pl = plot3(data(1, groupDataIndices),data(2,groupDataIndices),data(3,groupDataIndices), [markers(markerIndex) colors(colorIndex)]);                set(pl,'MarkerSize', 10);        % Set the plot to the default 3D view.        view(3);        % Set the camera projection type.        %    camproj('perspective');        camproj('orthographic');                % Advance to the next color, and marker if all of the colors have        % been used.        colorIndex = colorIndex+1;         if (colorIndex > colorCount),            colorIndex = 1;             markerIndex + 1;            if (markerIndex > markerCount),                markerIndex = 1;            end;        end;    end            xlabel('axis 1')    ylabel('axis 2')    zlabel('axis 3')    else     warning('Sorry, data must be of dimension 2 or 3 to be displayed by plot_data.m')    returnend% Restore original hold stateif ~originalHoldState,    hold off;end% Resize the figure window so that it is more readily visible.set(0,'Units','pixels');temp = (get(0,'ScreenSize'));screenColumns = temp(3);screenRows = temp(4);figureFillRatio = [.8 .5]; % Fraction of the columns and rows to fill up.screenCenter = floor([screenColumns/2 screenRows/2]);cornerOffset = floor([screenColumns*figureFillRatio(1)/2 screenColumns*figureFillRatio(2)/2]);set(gcf,'Position',[screenCenter - cornerOffset, 2*cornerOffset]);%set(gcf,'MenuBar','none')

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?