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)
  1 件のコメント
bes
bes 2012 年 10 月 3 日
Thanks a lot

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLighting, Transparency, and Shading についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by