Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

3D RGB plot in Matlab

Tags:

plot

matlab

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?

like image 466
Marta Sampietro Avatar asked Jul 22 '26 17:07

Marta Sampietro


1 Answers

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:

Result

Best,

like image 140
Ratbert Avatar answered Jul 24 '26 16:07

Ratbert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!