Clear Filters
Clear Filters

Plotting multilines with multi colours

2 views (last 30 days)
bes
bes on 16 Aug 2012
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?

Accepted Answer

bes
bes on 3 Oct 2012
scatter3(Vertices(:,1), Vertices(:,2), Vertices(:,3),1, Vertices(:, 4:6)/255, 'filled'); % 3D scatter plot

More Answers (2)

Image Analyst
Image Analyst on 16 Aug 2012
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 Comment
bes
bes on 3 Oct 2012
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)

Sign in to comment.


Matt Fig
Matt Fig on 16 Aug 2012
Edited: Matt Fig on 16 Aug 2012
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)

Categories

Find more on Discrete Data Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!