Color Proportional to Height in Scatter3()

6 ビュー (過去 30 日間)
Daniel
Daniel 2011 年 8 月 4 日
I am plotting data points in scatter3. The x and y coordinates are the location of a mirror, and the z value is the signal strength at that point. It ranges from 0 to 384.
I am trying to create a color array the same length as the data to be graphed in order to have different colors for the different heights. Right now I have this:
color=cell(384,1);
for j=1:384
if (signal{j} <40)
color(j)='r';
elseif (signal{j} >= 40) && (sigal{j} <100)
color(j)='g';
elseif signal{j} >=100
color(j)='b';
end
end
Basically I am trying to check the height of the point and based on the height, put a color code into a 384x1 array. However I keep getting this error code:
Cell contents reference from a non-cell array object. (It also points to this part:
if (signal{j} <40)
I am not sure why. The signal is a 384x1 double array.
Any help would be wonderful!

採用された回答

Walter Roberson
Walter Roberson 2011 年 8 月 4 日
pointsize = 8;
[counts, ccode] = histc(signal,[-inf, 40, 100, inf])
scatter3(x,y,signal,pointsize,ccode(:));
colormap([1 0 0;0 1 0; 0 0 1]);
  1 件のコメント
Daniel
Daniel 2011 年 8 月 4 日
That was amazing. Thanks so much!

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

その他の回答 (1 件)

Daniel
Daniel 2011 年 8 月 4 日
Ok...I got this to work...messed with the formatting and stuff,
but now it doesnt like a colormap of the data. It says
Array must be numeric or logical.
My formatting for scatter3 is
scatter3(x,y,z,colormatrix)
where colormatrix is a 385x1 matrix with entries of 'r','g','b'
sorta like {'r','g'.....}
Any ideas?

カテゴリ

Help Center および File ExchangeColor and Styling についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by