C = repmat([i],size(A{i},1),1);%create color matrix C
scatter3(A{i}(:,1),A{i}(:,2),A{i}(:,3),C,'filled');
的第四个输入参数
scatter3
C
,不指定颜色。它用于指定正在绘制的圆的大小。就因为你给它起了名字
C
,MATLAB不会自动识别您的意思是颜色。你会得到不同的颜色,因为你用
hold on
针对您的实际问题,从
my previous answer
,
newA = vertcat(A{:}); %Concatenating all matrices inside A vertically
numcolors = numel(A); %Number of matrices equals number of colors
colourRGB = jet(numcolors); %Generating colours to be used using jet colormap
colourtimes = cellfun(@(x) size(x,1),A);%Determining num of times each colour will be used
colourind = zeros(size(newA,1),1); %Zero matrix with length equals num of points
colourind([1 cumsum(colourtimes(1:end-1))+1]) = 1;
colourind = cumsum(colourind); %Linear indices of colours for newA
scatter3(newA(:,1), newA(:,2), newA(:,3), [] , colourRGB(colourind,:),'filled');
%However if you want to specify the size of the circles as well as in your
%original question which you mistakenly wrote for color, use the following line instead:
% scatter3(newA(:,1), newA(:,2), newA(:,3), colourind , colourRGB(colourind,:),'filled');
grid on;
view(3); %view in 3d plane
colormap(colourRGB); %using the custom colormap of the colors we used
%Adjusting the position of the colorbar ticks
caxis([1 numcolors]);
colorbar('YTick',[1+0.5*(numcolors-1)/numcolors:(numcolors-1)/numcolors:numcolors],...
'YTickLabel', num2str([1:numcolors]'), 'YLim', [1 numcolors]);
如果您想在代码中错误地更改圆的大小,请使用代码中提到的用于绘制的相关线。使用它可以生成以下结果: