2017-09-06 22 views
1

1×3セルA考えてみましょう:Aiの構造があるようです3Dプロットで異なる色のセルに各マトリックスをプロットするにはどうすればよいですか?

A = { [A1] [A2] [A3] } 
A = {[1 2 3; 4 5 6; 7 8 9] [6 5 4; 9 8 7] [1 1 1]} 

を:

A1 = [ 1 2 3 %coordinate (x,y,z) of point 1 
     4 5 6 %coordinate (x,y,z) of point 2 
     7 8 9 ] %coordinate (x,y,z) of point 3 

A2 = [ 6 5 4 %coordinate (x,y,z) of point 4 
     9 8 7 ] %coordinate (x,y,z) of point 5 

A3 = [ 1 1 1 ] %coordinate (x,y,z) of point 6 

我々はA1のすべてのポイントのために一つの色を使用するように、すべてのこれらの点をプロットする方法、 A2のすべての点のための別の色とA3のすべての点のためのいくつかの他の色?

一般に、1xnのセル、つまりA = { [A1] [A2] [A3] ... [An] }がある場合、これはどのように行うことができますか?

答えて

1

セル配列内のすべての行列を連結します。Avertically異なる行列に異なる色を生成するには、jetまたはany other colormapを使用します。 A内の各マトリックスの点数を求め、各色の繰り返し回数を決定します。それに応じて各色のコピー数を生成し、最後にscatter3を使用してこれらの点をプロットします。所与Aについて

newA = vertcat(A{:});     %Concatenating all matrices inside A vertically 

colours = jet(numel(A));     %Generating colours to be used 
colourtimes = cellfun(@(x) size(x,1),A); %Determining num of times each colour wil 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),[], colours(colourind,:),'filled'); 

、上記のコードは、この結果を生成する:

output

関連する問題