MATLAB: Adding a colorbar to a figure

colorbarImage Processing Toolbox

Hi, I am trying to display a colorbar in a figure. So some background on what I am doing: I am tracking objects (from images) in 3D and in time. I wanted to just visualize the tracking so I am plotting the x and y position of an object as a circle and then color-code the circle to represent z. The way I color code is I check at what z position an object is and then assign it a color (see below).
The code is something like this:
figure;
% display the original image
imshow(image)
hold on
% loop through the data and check z position to color-code
for j = 1:n
viscircles(data(j,1:2,radius(j),'color',colors(round(data(j,3)),:));
end
where the columns in 'data' are the x, y, z positions and 'colors' is a colormap that I defined for certain z values. So I get an image something like the one attached.
So I was wondering if anyone could point me in a direction for how to add a colorbar in the figure to provide information about the z position? Any help would be greatly appreciated, thanks!

Best Answer

Use the colorbar(), colormap(), and caxis() functions.
Related Question