This should be simple, but I'm having trouble getting the scaling of a custom color map to match the range of values that I'm plotting. I don't quite understand how to get the range on the colorbar to match the range of the Z-dimension data. Here's a simple example that I'm trying to get working:
maxval = 5;
num = 10;
X = linspace(0,maxval,num);
Y = linspace(0,maxval,num);
Z = linspace(0,maxval,num);
cMap = interp1([0;1],[1 .5 0; .5 1 0],linspace(0,1,num));
scatter3(X,Y,Z,50,cMap,'Filled');
view(-75,20);
colormap(cMap)
colorbar
Which gives this:

I want the top value in the colorbar to be 5 in this example. I've tried modifying the [0;1] in the interp1 function, but I can't seem to get the correct settings.
I'm using version 2017a, if that matters.