Plotting multilines with multi colours
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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?
0 commentaires
Réponse acceptée
Plus de réponses (2)
Image Analyst
le 16 Août 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.
Matt Fig
le 16 Août 2012
Modifié(e) : Matt Fig
le 16 Août 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)
Voir également
Catégories
En savoir plus sur Discrete Data Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!