Skip to content

Instantly share code, notes, and snippets.

@Remi-Gau
Created June 29, 2022 07:22
Show Gist options
  • Save Remi-Gau/d9bc15a075fa65c6469680208976067a to your computer and use it in GitHub Desktop.
Save Remi-Gau/d9bc15a075fa65c6469680208976067a to your computer and use it in GitHub Desktop.
multidimensional scaling example in matlab
X = [ normrnd(0,1,10,3) normrnd(0,.1,10,1) ]; % generate data
D = pdist(X, 'euclidean'); % compute euclidiant distance
% do multidimensional scaling
% find a configuration with those inter-point distances
% If the first k elements of E are much larger than the remaining (n-k), then you
% can use the first k columns of Y as k-dimensional points, whose interpoint
% distances approximate D. This can provide a useful dimension reduction for
% visualization, e.g., for k==2.
[Y, e] = cmdscale(D);
scatter(Y(:,1), Y(:,2))
xlabel('dimension 1')
ylabel('dimension 2')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment