I want to plot 3D color image from data in array by using Plot3

4 views (last 30 days)
I have x,y,z and RGB in array.
plot3 (objectpoint_x_array(:), objectpoint_y_array(:), objectpoint_z_array(:),'Color' , [objectpoint_color_array(:,:,1) objectpoint_color_array(:,:,2) objectpoint_color_array(:,:,3)]);
There is an error.
" Error using plot3
Color value must be a 3 or 4
element vector "
Houghton on 19 Aug 2015
I calculate (x,y,z) coordinate from images and I want to plot them in 3D where each coordinate will show the color from the reference image.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 18 Aug 2015
You cannot use the 'Color' parameter of plot3() to designate more than one color.
plot3() generates one lineseries object for each column of Z. You can loop through the line handles giving each of the handles a different color. You cannot, however, give each point a different color.
If you want to give each point a different color then you need to use scatter3() or you need to use patch()
  1 Comment
Walter Roberson
Walter Roberson on 19 Aug 2015
plot3() is primarily for drawing lines that might or might not have markers on them: the data is in some way ordered . plot3() creates lineseries objects. Each lineseries object can have only a single color and single marker shape. The only way to use plot3() with one color for each point would be if you plotted one point at a time, which is possible but not pleasant code.
The routine for plotting in 3D with potentially different colors for each point is scatter3(), which is happy to take an N x 3 color matrix where N is the number of points being plotted. But scatter3() is for unordered data and cannot draw lines between the points.
If you want both lines and per-point coloring then you need to use patch(), and you need to decide what color you want each line to be. You currently have data about vertex colors but no indication of how to decide the color of lines joining the vertices, since the vertices may be different colors. patch() offers a few different options as to how to determine the color for lines.
Considering the task described it sounds to me as if scatter3() would be fine, but I cannot be sure as you did try to use the line-drawing routine plot3().

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!