Color Proportional to Height in Scatter3()

5 次查看(过去 30 天)
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
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 CenterFile Exchange 中查找有关 Color and Styling 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by