Plotting multilines with multi colours

1 次查看(过去 30 天)
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