필터 지우기
필터 지우기

Drawing colored line segments in a 3d plot

조회 수: 13 (최근 30일)
Harry
Harry 2020년 7월 13일
답변: Image Analyst 2020년 7월 13일
I have code that produces quite nice looking 3d graphs showing line segments.
Currently, i can make the points at the end of each line segment match each other- but i can't work out how to make the line segment match the points at its ends.
A = rand(6,50);
%create 3d points to be graphed
startv = [A(:,1),A(:,3),zeros(length(A),1)];
endv = [A(:,2),A(:,5),A(:,4)];
%I want to use the vector endv to determine the colour of the lines/points
%to make the graph clearer; so i am going to create a color vector by
%transforming it
colorv=endv./max(endv)
figure;hold on
scatter3(startv(:,1),startv(:,2),startv(:,3),10,colorv,'filled');
scatter3(endv(:,1),endv(:,2),endv(:,3),10,colorv,'filled');
h = plot3([startv(:,1)';endv(:,1)'],...
[startv(:,2)';endv(:,2)'],...
[startv(:,3)';endv(:,3)'])
set(h,'color',[128,0,128]./255);
this graph illustrates the above; in this case some data is being displayed (and this means one variable is always close to 100), but i think it would be easier to understand if the lines were the same colour as their ends

채택된 답변

Image Analyst
Image Analyst 2020년 7월 13일
If you call plot3 in a loop, you can plot one line at a time with colorv. Something like (untested)
for k = 1 : size(startv, 1)
plot3([startv(k,1)';endv(k,1)'],...
[startv(k,2)';endv(k,2)'],...
[startv(k,3)';endv(k,3)'], '.-',...
'LineWidth', 2, 'Color', colorv(k,:), 'MarkerSize', 30);
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by