I have a 3-by-4 matrix in which each column has the 3 components R, G and B of a particular color. I need to plot each component in a 3D plot as a single point and, if possible, paint each of the points with the color of the RGB components that correspond to it.
I have tried with the plot3
function, but it paints a continuous line, and it has only one color.
For example, this is my matrix:
centroids =
47 85 104 126
37 66 86 103
36 55 71 90
where (47,37,36)
are the RGB coordinates of the first point, therefore I need to plot it as a single point in the RGB space and with this particular color. My idea was to have a for loop like this:
for i = 1:4
plot3( centroids(1,i),centroids(2,i),centroids(3,i),'Color',centroids(:,i))
end
But it gives me an error, and it I do not try to change the color, it paints only a line and with the same color. Is there a way to plot each column of the matrix as an independent point and with the color of the RGB components?
You should use the scatter3
function instead. Here is a sample with your data, assuming it is contained in an array called A
:
scatter3(A(1,:), A(2,:), A(3,:), 50, (A/255)', 'filled')
and the result:
Best,
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.