YTickLabel将在Matlab中显示一些指定值(不是全部显示)

YTickLabel将在Matlab中显示一些指定值(不是全部显示),matlab,colormap,Matlab,Colormap,我的代码和结果如下: %% How to plot each matrix in a cell in 3d plot(1 matrix with 1 color) ? % Generate Sample data cell A(1x10 cell array) clear; clc; A = cell(1,10); % cell A(1x10 cell array) for kk = 1:numel(A) z = 10*rand()+(0:pi/50:10*rand()*pi)'; x

我的代码和结果如下:

%% How to plot each matrix in a cell in 3d plot(1 matrix with 1 color) ?
% Generate Sample data cell A(1x10 cell array)
clear; clc;
A = cell(1,10); % cell A(1x10 cell array)
for kk = 1:numel(A)
  z = 10*rand()+(0:pi/50:10*rand()*pi)';
  x = 10*rand()*sin(z);
  y = 10*rand()*cos(z);
  A{kk} = [x,y,z];
end  
A_6 = A(1:6);        % generate a cell with the first 6 matrices in "A" cell array 
                     % The numer "6" can be changed to be any number which you want to plot them by colormap                      
newA = vertcat(A_6{:});                   %Concatenating all matrices inside A vertically
numcolors = numel(A_6);                   %Number of matrices equals number of colors
colourRGB = hsv(numcolors);             %Generating colours to be used using hsv colormap
colourtimes = cellfun(@(x) size(x,1),A_6);%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');
%if you want to specify the size of the circles, 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]);
我有这样的形象:

我如何显示带有某些指定值的“YTickLabel”(不是全部显示),如下图所示


要删除标签上的某些记号,只需相应地设置颜色栏的
'YTick'
属性。也就是说,将最后一行替换为以下内容:

colorbar('YTick', [1 3 5 6], 'YLim', [1 numcolors])

将注释中的代码带到上一个答案:

h = colorbar('YTick',[1:numcolors],'YTickLabel', num2str([1:numcolors]'), 'YLim', [1 numcolors]); set(h, 'Ticklabels', {1 [] 3 [] 5 6}); set(h, 'Ticks', {1 3 5 6});
现在仅为4个刻度设置6个刻度标签。如果将记号设置为正确的值,则自动生成的记号标签将是您想要的

请尝试以下操作:

h = colorbar('YTick',[1:numcolors],'YTickLabel', num2str([1:numcolors]'), 'YLim', [1 numcolors]); 
set(h, 'Ticks', {1 3 5 6});

我也不想显示“ticklebels”对应的“Ticks”(请参见图中的问题)?如何可以?我添加代码如下。但它与我的预期不同:
h=colorbar('YTick',[1:numcolors],'yticklab',num2str([1:numcolors]),'YLim',[1 numcolors]);集合(h,'Ticklabels',{1[]3[]5});集合(h,'Ticks',{1 3 5 6})