我有以下代码在Matlab上创建和绘制螺旋线。我想控制颜色并自己添加三到四种颜色,而不是 matlab 进行着色。我怎样才能自己设置颜色并控制颜色?这是我的代码:
N = 1000;
r = linspace(0,1,N);
t = (3*pi/2)*(1+2*r);
x(1,:) = t.*cos(t);
x(2,:) = t.*sin(t);
x(3,:) = zeros(1,N);
ms = 50;
%cm = colormap;
%cm(64,:);
figure;
scatter3(x(1,:), x(2,:), x(3,:), ms, t, 'filled');
请问有什么帮助吗?
@jucestain,着色工作,谢谢。我还有一个问题。如果像这样在上面的代码中添加噪音,结果会变得有趣,如图所示
N = 1000;
r = linspace(0,1,N);
t = (3*pi/2)*(1+2*r);
x(1,:) = t.*cos(t);
x(2,:) = t.*sin(t);
x(3,:) = zeros(1,N);
% Set colors:
t(1:250) = 1;
t(251:500) = 2;
t(501:750) = 3;
t(751:1000) = 4;
ms = 50;
figure;
scatter3(x(1,:), x(2,:), x(3,:), ms, t, 'filled');
%add noise
x(1,:) = x(1,:) + 5*randn(1,N);
x(2,:) = x(2,:) + 5*randn(1,N);
x(3,:) = x(3,:) + 5*randn(1,N);
figure;
scatter3(x(1,:), x(2,:), x(3,:), ms, t, 'filled');
这个情节的结果很笨拙,我不知道为什么?我是在正确地添加噪音还是什么?剧情对吗?