Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
|
![]() |
#1 |
高级会员
注册日期: 2019-11-21
帖子: 3,006
声望力: 66 ![]() |
![]()
我将3组数据进行了PCA分组。我想用不同的颜色突出显示每个变量组。在此之前,我覆盖了3个双线。这会产生不同的颜色,但是会由于每个双图函数使数据倾斜而在数据中产生失真。这导致所有组的偏斜量都不同,从而使图不正确。
如何获取PCA分数矩阵(30x3)并将其拆分,以使第一个10x3是一种颜色,接下来的10x3是另一种颜色,而第三个10x3是另一种颜色,而又不会歪曲数据? 回答: 这是我用来绘制具有不同颜色的双图数据的方法。绘制之前的代码行来自biplot.m文件。使用重叠双图时,双图处理数据的方式保持完整,并停止数据倾斜。 这种编码不是最有效的,可以看到可以切割的部分。我想保持代码完整无缺,以便可以看到biplot的整体工作方式。 %%%%%%%%%%%%%%%%%%%%% xxx = coeff(:,1:3); yyy= score(:,1:3); **%Taken from biplot.m; This is alter the data the same way biplot alters data - having the %data fit on grid axes no larger than 1.** [n,d2] = size(yyy); [p,d] = size(xxx); %7 by 3 [dum,maxind] = max(abs(xxx),[],1); colsign = sign(xxx(maxind + (0:p:(d-1)*p))); xxx = xxx .* repmat(colsign, p, 1); yyy= (yyy ./ max(abs(yyy(:)))) .* repmat(colsign, 42, 1); nans = NaN(n,1); ptx = [yyy(:,1) nans]'; pty = [yyy(:,2) nans]'; ptz = [yyy(:,3) nans]'; **%I grouped the pt matrices for my benefit** plotdataholder(:,1) = ptx(1,:); plotdataholder(:,2) = pty(1,:); plotdataholder(:,3) = ptz(1,:); **%my original score matrix is 42x3 - wanted each 14x3 to be a different color** scatter3(plotdataholder(1:14,1),plotdataholder(1:14,2),plotdataholder(1:14,3),35,[1 0 0],'marker', '.'); hold on; scatter3(plotdataholder(15:28,1),plotdataholder(15:28,2),plotdataholder(15:28,3),35,[0 0 1],'marker', '.') ; scatter3(plotdataholder(29:42,1),plotdataholder(29:42,2),plotdataholder(29:42,3),35,[0 1 0],'marker', '.'); xlabel('Principal Component 1'); ylabel('Principal Component 2'); zlabel('Principal Component 3'); 更多&回答... |
![]() |
![]() |