2017-09-08 10 views
0

この質問はmy previous postにリンクしています。私は、「カラーマップを使用する場合は
:私の質問3Dプロットでのカラーマップの使用方法は?

output

:これは上記のコードからの画像結果である

%% 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 

% Plot point of each matrix in one figure with different color 
figure 
hold on; 
for i = 1:numel(A)%run i from 1 to length A 

    C = repmat([i],size(A{i},1),1);%create color matrix C 
    scatter3(A{i}(:,1),A{i}(:,2),A{i}(:,3),C,'filled'); 
end 
grid on; 
view(3); % view in 3d plane 
colorbar; 

は、以下のコードを考えてみましょう"マトリックスの数に対応する色を表示するには、どのように行うことができますか?
例:投稿コードでが、私は10個の行列(A{1}A{2}A{3}、...、A{10})セルA内部を持っているので、どのようにカラーバーを作るためにプロットに使用10色を表示し、どのようにプロットで使用されている10色に対応する1から10までの10の数値を表示します(画像に示されています)。あなたの次のコード行で

答えて

1

C = repmat([i],size(A{i},1),1);%create color matrix C 
scatter3(A{i}(:,1),A{i}(:,2),A{i}(:,3),C,'filled'); 

あなたがCという名前scatter3の4番目の入力引数は、色を指定していません。プロットされる円のサイズを指定するためのものです。 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]); 

:あなたは、円の大きさなどを変更したい場合は

out1

あなたが間違ってあなたのコードでやっていた、コードに記載されているプロットのための関連行を使用してください。これを使用すると、次の結果が生成されます。

out2

関連する問題