필터 지우기
필터 지우기

How to assign gradual color to a 3d line based on values of another vector

조회 수: 198 (최근 30일)
Hi all, I want to assign colour to lines plotted between 3dpoints, based on the values of a fourth vector. The values of the fourth vector are not sorted in any way, and they are both positive and negative values. I did a for loop to plot a line between the nodes that have connectivity, and I'm assigning the color as well. I think I'm having problems with the way I'm sorting the fourth value. But can't figure it out how to make it work. Here is the code:
myColourMap=jet(m);
s=stresses;
[s,I]=sort(s);
for i=1:m
Intensity = I(i);
LineColour=myColourMap(Intensity,:);
plot3([ x(t1(i)) x(t2(i))], [ y(t1(i)) y(t2(i))], [ z(t1(i)) z(t2(i))],'Color', LineColour)
hold on
end
axis equal
colorbar
The four vector is the 's' vector, and when I plotted the network of lines, the colour it assign to each one, does not represent the ascending or descending of the values in vector s(which represent stresses). I appreciate very much any help of how to plot the lines based on the values of a vector, or if the problem is the sorting, then, how to obtain the ordering indices of the vector s.
Thanks a lot in advance
Martha

채택된 답변

Mike Garrity
Mike Garrity 2015년 11월 13일
Unfortunately the line object that plot and plot3 create can't do color data interpolation. Several of the other objects can. The one that is most commonly used for this is patch. Probably because patch can do just about anything.
There's one thing to look out for when using patch for this. By default, it makes a closed loop like this:
t = linspace(0,2*pi,100);
x = cos(t);
y = sin(t);
z = t;
c = cos(t).^2;
colormap(hsv)
patch(x,y,z,c,'FaceColor','none','EdgeColor','interp')
colorbar
view(3)
You need to add a nan to tell it not to do that.
t = linspace(0,2*pi,100);
x = cos(t);
y = sin(t);
z = t;
c = cos(t).^2;
colormap(hsv)
patch([x nan],[y nan],[z nan],[c nan],'FaceColor','none','EdgeColor','interp')
colorbar
view(3)
  댓글 수: 5

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by