📄 plot_subspaces2.m
字号:
% Code for rendering two dimensional results generated by the gpca% algorithm. Users should call plot_subspacesfunction pl = plot_subspaces2(data, labels, groupBases, basisDimensions)CENTER_DATA = false;% Generate a list, existList, of labels that have had points assigned to them.highestLabel = max(labels);existList = zeros(highestLabel, 1); % existList will have at most highestLabel elements.groupCount = 0;for labelIndex = 1:highestLabel, if (sum(labels == labelIndex) > 0) % If the group has at least one element in it, groupCount = groupCount + 1; existList(groupCount) = labelIndex; end;end;existList = existList(1:groupCount);markers = '.ox+*svp^h<>'; markerCount = length(markers); markerIndex = 1;colors = 'rbgmcyk'; colorCount = length(colors); colorIndex = 1;% Hold while drawing a bunch of elements to the current figure.originalHoldState = ishold;hold on;% Iterate through every group that contains at least one element.for groupIndex = 1:groupCount, % % Plot the data points in the current group with unique colors and shapes. % groupDataIndices = find(labels == existList(groupIndex)); % pl = plot(data(1, groupDataIndices),data(2,groupDataIndices), ['.' colors(colorIndex)]); % set(pl,'MarkerSize',5); basis = groupBases{existList(groupIndex)}(:,1:basisDimensions(existList(groupIndex))); groupData = data(:, labels == existList(groupIndex)); center = mean(groupData,2); if (size(basis,2) ~= 1), error('Trying to plot a subspace of dimension other than one in a two dimensional subsspace'); end % Plot the one dimensional subspace (line) x = basis(1); y = basis(2); if(CENTER_DATA), projected_data = (groupData' - ones(size(groupData , 2) , 1) * center') * basis; upper_bound = max(projected_data) * basis + center; lower_bound = min(projected_data) * basis + center; l = line([upper_bound(1) lower_bound(1)], [upper_bound(2) lower_bound(2)]); set(l, 'Color', colors(colorIndex)); set(l, 'LineWidth', 3); else projected_data = (groupData') * basis; upper_bound = max(projected_data) * basis; lower_bound = min(projected_data) * basis; l = line([upper_bound(1) lower_bound(1)], [upper_bound(2) lower_bound(2)]); set(l, 'Color', colors(colorIndex)); set(l, 'LineWidth', 3); end % Advance to the next color and marker. markerIndex = markerIndex + 1; if (markerIndex > markerCount) markerIndex = 1; end; colorIndex = colorIndex+1; if (colorIndex > colorCount) colorIndex = 1; end;end;xlabel('axis 1')ylabel('axis 2')pl = [];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -