MATLAB: What does a tilde (~) inside square brackets mean

bracketskmeanspalettesquaretilde

[~, Palette] = kmeans(reshape(B(:),M*N,3),8,'E','s','S','U');
Specifically, what does the ~ inside the square brackets represent (e.g. a matrix with multiple LHS assignment)?

Best Answer

The function kmean can be used with two outputs :
[IDX,C] = kmeans(X,k)
Here you use the brackets to define the two outputs (it is not an array). Here, IDX will be the first output (a vector containing the cluster indices of each point) and C will be the second one (a matrix containing the cluster centroid locations).
So the brackets don't mean that you have just one ouput (an array), but they are used to gather the outputs.
And whatever happens, IDX will be the first output and C the second one.
But if you just want to know C (and you don't care IDX), it is not usefull to assign this value to a variable.
So, when you use [~,palette], that means that you just want the second output of your function, and do not care the first one.
Use this is helpfull for you (you don't have many useless variables in your workspace), and is faster!