0

如何在 matlab 中使用 scatter3 plot 可视化具有大量特征的数据集。我已经使用 PCA 将其减少到三个功能,但是如何根据相应行的 y 值(或标记值)是 1 还是 0,让它以不同的颜色显示?PS PCA 返回一个 [675 x 3] 矩阵,它是数据集中的 675 个示例,具有前 3 个主成分。

4

2 回答 2

2
% Create some data to represent the results of PCA
x = rand(675,3); y = randi([0,1],675,1);

% Plot with markers of size 10
scatter3(x(:,1),x(:,2),x(:,3),10,y)

比其他地方建议的循环和 if 语句方法要容易一些。

于 2012-05-11T08:42:00.100 回答
1

我的 matlab 不是最新的,但我相信你可以通过首先设置hold on然后循环并使用 plot3 绘制矩阵的每一行,并根据标签设置颜色来做到这一点。例如

hold on
for i=1:675,
    if (label == 1)
        plot3(mat(i,1), mat(i,2), mat(i,3), '-xr');
    elseif (label == 2)
        plot3(mat(i,1), mat(i,2), mat(i,3), '-og');
    elseif (label == 3)
        plot3(mat(i,1), mat(i,2), mat(i,3), '-b');
    end
end
hold off

不过,这可能需要一些调整,因为我使用 Matlab 已经有一段时间了。希望能帮助到你 :-)

于 2012-05-11T00:34:42.420 回答