How to add different color for each galaxy

5 ビュー (過去 30 日間)
Christos Dimopoulos
Christos Dimopoulos 2017 年 12 月 7 日
コメント済み: Christos Dimopoulos 2017 年 12 月 27 日
I am working on "Spiral Galaxy Formation Simulation" example in Mathworks. How can I add different colors for each galaxy's bodies? There is an option in each galaxy function for color but it doesn't work.
  1 件のコメント
Christos Dimopoulos
Christos Dimopoulos 2017 年 12 月 9 日
編集済み: Christos Dimopoulos 2017 年 12 月 10 日
I have bodies with 8 properties. Last one is color. In each galaxy's bodies I give the same color, but different than other galaxy bodies.
bodies(i,8) = 'r';
When trying to plot seems I can't get it to color each body separately.
for i = 1:n,
points_x(i) = bodies(i,2);
points_y(i) = bodies(i,3);
points_z(i) = bodies(i,4);
points_col(i) = bodies(i,8);
end
% Remove the old plot.
if isempty(oldPlot)
oldPlot = fig;
elseif ~isempty(foundFig)
delete(oldPlot);
end
oldPlot = plot3(points_x,points_y,points_z, points_col);
drawnow
I get error: "An error occurred while running the simulation and the simulation was terminated Caused by: Not enough input arguments."
it only accepts one color for all
oldPlot = plot3(points_x,points_y,points_z, 'w.');
It might be the dot, I don't know...

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2017 年 12 月 10 日
Use scatter3() instead of plot3() if you want to specify a color for each and every marker.
  7 件のコメント
Image Analyst
Image Analyst 2017 年 12 月 22 日
You can have the indexes be variables, like points_x(indexes(1):indexes(2)) etc.
I don't know why you're deleting the old plot. Why not simply call "cla reset" if you want to wipe everything clean?
Christos Dimopoulos
Christos Dimopoulos 2017 年 12 月 27 日
You are correct again!
cla fixed it!
cla reset unfortunately makes the axis appear from nowhere and loses its focus.
Anyway if it works with cla I am ok.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePerformance and Memory についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by