MATLAB: How to control the number of labels plotted using CLABEL

clabelcontourlabelsMATLABnumberof

I want just one label per contour when using CLABEL.

Best Answer

There is no direct way of specifying the number of labels to plot on the contour. However, if you need just one label per contour, you can use call the CLABEL with just one parameter, the contour matrix output. For example:
[X,Y] = meshgrid(-2:.2:2,-2:.2:3);
Z = X.*exp(-X.^2-Y.^2);
[c h] = contour( X, Y,Z);
clabel(c) % This will produce only one label per contour.
PLEASE NOTE: The position of these labels will be random.
Alternately, you can use the manual mode for CLABEL as follows:
clabel(c, 'manual')
This will give you the complete control of where to place the labels with the help of the mouse.
The other way around is to specify the 'labelspacing' property of the CLABEL as follows:
clabel(c,h, 'labelspacing', 700);
This will space the labels on each contour by 700 pixel length. You can adjust this length until you get the desired results.