Matlab code can be downloaded at this link.

Matlab code for 2-d Isomap generation using eucledian?tangential distance
close all;
clear all;
load mnist
M = 3000;
% option - 1 : Eucledian Distance
% option - 2 : Tangential Distance
option = 1;
train_x = train_x';
train_y = train_y';
val = find(train_y(1:end,1))-1;
for j=2:M;
val = [val find(train_y(1:end,j))-1];
end
data = train_x(1:end,1:M);
data = double(data);
switch option
case 1
D = L2_distance(data,data,1);
case 2
D = tangent_d(data,data);
end
options.dims = 1:10;
[Y, R, E] = Isomap(D, 'k', 7, options);
% Y.coords{2} contains coordinates for 2-dimensional embeddings
% Y.index contains the indices of the points embedded
x_2d_coord = Y.coords{2}(1,1:end);
y_2d_coord = Y.coords{2}(2,1:end);
ind0 = find(val == 0);
ind1 = find(val == 1);
ind2 = find(val == 2);
ind3 = find(val == 3);
ind4 = find(val == 4);
ind5 = find(val == 5);
ind6 = find(val == 6);
ind7 = find(val == 7);
ind8 = find(val == 8);
ind9 = find(val == 9);

X0 = x_2d_coord(ind0);
X1 = x_2d_coord(ind1);
X2 = x_2d_coord(ind2);
X3 = x_2d_coord(ind3);
X4 = x_2d_coord(ind4);
X5 = x_2d_coord(ind5);
X6 = x_2d_coord(ind6);
X7 = x_2d_coord(ind7);
X8 = x_2d_coord(ind8);
X9 = x_2d_coord(ind9);

Y0 = y_2d_coord(ind0);
Y1 = y_2d_coord(ind1);
Y2 = y_2d_coord(ind2);
Y3 = y_2d_coord(ind3);
Y4 = y_2d_coord(ind4);
Y5 = y_2d_coord(ind5);
Y6 = y_2d_coord(ind6);
Y7 = y_2d_coord(ind7);
Y8 = y_2d_coord(ind8);
Y9 = y_2d_coord(ind9);

figure
plot(X1,Y1,'r.');text(X1,Y1,num2str(1));

hold;
plot(X7,Y7,'b.');text(X7,Y7,num2str(7));
title('Ba. Clusters of 1 and 7 using Euclidean/Tangential Distance with 1 in red and 7 in blue');

figure
plot(X4,Y4,'r.');text(X4,Y4,num2str(4));
hold;
plot(X9,Y9,'b.');text(X9,Y9,num2str(9));
title('Bb. Clusters of 4 and 9 using Euclidean/Tangential Distance with 4 in red and 9 in blue');

figure
hold all
plot(X0,Y0,'b.');text(X0,Y0,num2str(0));
plot(X1,Y1,'go');text(X1,Y1,num2str(1));
plot(X2,Y2,'m.');text(X2,Y2,num2str(2));
plot(X3,Y3,'y.');text(X3,Y3,num2str(3));
plot(X4,Y4,'c.');text(X4,Y4,num2str(4));
plot(X5,Y5,'k.');text(X5,Y5,num2str(5));
plot(X6,Y6,'bo');text(X6,Y6,num2str(6));
plot(X7,Y7,'ro');text(X7,Y7,num2str(7));
plot(X8,Y8,'co');text(X8,Y8,num2str(8));
plot(X9,Y9,'g.');text(X9,Y9,num2str(9));
x_lim1 = xlim;
y_lim1 = ylim;
x_len = x_lim1(2) - x_lim1(1);
y_len = y_lim1(2) - y_lim1(1);
for i=1:M
if val(i) == 2
matr = vec2mat(train_x(1:end,i),28);
colormap(gray);
imagesc([x_2d_coord(i),x_2d_coord(i)+(x_len/60)],[y_2d_coord(i),y_2d_coord(i)-(y_len/40)],matr);
end
end
title('Bc. Clusters for all the digits using Euclidean/Tangential Distance');