Plotting multilines with multi colours

조회 수: 1 (최근 30일)
bes
bes 2012년 8월 16일
I have a very big matrix called Vertices (100000 X 6 matrix) First 3 columns have x y z points. last 3 columns have the colour of that point. for eg first 2 rows are
7645 383 3 49 47 39
7649 382 4 38 37 31
I need to plot all the points with the defined colors.
for ii = 1:1000
plot3(Vertices(ii,1), Vertices(ii,2), Vertices(ii,3), 'color',[Vertices(ii,4)/255, Vertices(ii,5)/255, Vertices(ii,6)/255], 'Marker', '.');
hold on;
end
This works. I have tried for first 1000 element. But since my matrix size is very large. It take a lot of time if i plot using loop. Is there any easy way to plot this?

채택된 답변

bes
bes 2012년 10월 3일
scatter3(Vertices(:,1), Vertices(:,2), Vertices(:,3),1, Vertices(:, 4:6)/255, 'filled'); % 3D scatter plot

추가 답변 (2개)

Image Analyst
Image Analyst 2012년 8월 16일
You can make this into an RGB image and then display with the image() or imshow() command. It will be much much faster that way. The only downside is that you'll have to pick a projection, like you're looking along the z axis so that you are basically looking at the x-y plane, and you won't be able to interactively rotate your 3D scatterplot of points.
  댓글 수: 1
bes
bes 2012년 10월 3일
Thanks. I have used scatter3
scatter3(Vertices(:,1), Vertices(:,2), Vertices(:,3),1, Vertices(:, 4:6)/255, 'filled');
It works fine. we can rotate this 3D plot (take time to rotate because of the computer hardware limitation for large amount of points)

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


Matt Fig
Matt Fig 2012년 8월 16일
편집: Matt Fig 2012년 8월 16일
Here is an example. If you put a tic/toc around the loop and the call to PATCH you will see that the call to PATCH is several thousand times faster. This is mainly because each call to PLOT3 creates a whole new graphics object, which takes time and memory.
% First make some data to match what you show....
[x,y] = meshgrid(-pi:.1:pi,-pi:.1:pi);
z = cos(x+y);
DAT = [x(:) y(:) z(:) round(rand(numel(x),3)*255)]; % The mx6
% Now on to the plotting. Use two methods and compare.
% First your method.
figure('pos',[30 30 1500 900])
subplot(1,2,1)
hold
for ii = 1:numel(x)
plot3(DAT(ii,1),DAT(ii,2),DAT(ii,3),...
'color',DAT(ii,4:6)/255,'Marker','.');
end
title('For loop')
view(47.5,60)
% Next do it with one function call, and compare.
subplot(1,2,2)
P = patch('xdata',DAT(:,1),'ydata',DAT(:,2),'zdata',DAT(:,3),...
'facevertexcdata',DAT(:,4:6)/255,...
'facecolor','none','edgecolor','none',...
'marker','.','markersize',8,...
'markeredgecolor','flat',...
'markerfacecolor','flat');
title('For loop')
view(47.5,60)

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by