📄 examplebutton_callback.m
字号:
function ExampleButton_Callback(hObject, eventdata, handles)
% --- Executes on button press in ExampleButton.
exampleValue = get(handles.ExampleMenu,'Value');
N = round(str2double(get(handles.PointsEdit,'String'))); % Number of points to use.
N = max(1,N);
ExParam = str2double(get(handles.ParamEdit,'String')); % Second parameter for example
ExParam = max(0.0,ExParam);
switch exampleValue
case 1 % Swiss Roll
tt = (3*pi/2)*(1+2*rand(1,N));
height = 21*rand(1,N);
handles.X = [tt.*cos(tt); height; ExParam*tt.*sin(tt)]';
handles.ColorVector = tt';
updateString{1} = 'Swiss Roll example loaded.';
case 2 % Swiss Hole
% Swiss Roll w/ hole example taken from Donoho & Grimes
tt = (3*pi/2)*(1+2*rand(1,2*N));
height = 21*rand(1,2*N);
kl = repmat(0,1,2*N);
for ii = 1:2*N
if ( (tt(ii) > 9)&(tt(ii) < 12))
if ((height(ii) > 9) & (height(ii) <14))
kl(ii) = 1;
end;
end;
end;
kkz = find(kl==0);
tt = tt(kkz(1:N));
height = height(kkz(1:N));
handles.X = [tt.*cos(tt); height; ExParam*tt.*sin(tt)]';
handles.ColorVector = tt';
updateString{1} = 'Swiss Hole example loaded.';
case 3 % Corner Planes
k = 1;
xMax = floor(sqrt(N));
yMax = ceil(N/xMax);
cornerPoint = floor(yMax/2);
for x = 0:xMax
for y = 0:yMax
if y <= cornerPoint
X(k,:) = [x,y,0];
ColorVector(k) = y;
else
X(k,:) = [x,cornerPoint+(y-cornerPoint)*cos(pi*ExParam/180),(y-cornerPoint)*sin(pi*ExParam/180)];
ColorVector(k) = y;
end;
k = k+1;
end;
end;
handles.X = X;
handles.ColorVector = ColorVector';
updateString{1} = 'Corner Planes example loaded.';
case 4 % Punctured Sphere by Saul & Roweis
inc = 9/sqrt(N); %inc = 1/4;
[xx,yy] = meshgrid(-5:inc:5);
rr2 = xx(:).^2 + yy(:).^2;
[tmp ii] = sort(rr2);
Y = [xx(ii(1:N))'; yy(ii(1:N))'];
a = 4./(4+sum(Y.^2));
handles.X = [a.*Y(1,:); a.*Y(2,:); ExParam*2*(1-a)]';
handles.ColorVector = handles.X(:,3);
updateString{1} = 'Punctured Sphere example loaded.';
case 5 % Twin Peaks by Saul & Roweis
inc = 1.5 / sqrt(N); % inc = 0.1;
[xx2,yy2] = meshgrid(-1:inc:1);
zz2 = sin(pi*xx2).*tanh(3*yy2);
xy = 1-2*rand(2,N);
handles.X = [xy; sin(pi*xy(1,:)).*tanh(3*xy(2,:))]';
handles.X(:,3) = ExParam * handles.X(:,3);
handles.ColorVector = handles.X(:,3);
updateString{1} = 'Twin Peaks example loaded.';
case 6 % 3D Clusters
numClusters = ExParam;
numClusters = max(1,numClusters);
Centers = 10*rand(numClusters,3);
D = L2_distance(Centers',Centers',1);
minDistance = min(D(find(D>0)));
k = 1;
N2 = N - (numClusters-1)*9;
for i = 1:numClusters
for j = 1:ceil(N2/numClusters)
X(k,1:3) = Centers(i,1:3)+(rand(1,3)-0.5)*minDistance/sqrt(12);
ColorVector(k) = i;
k = k + 1;
end;
% Connect clusters with straight line.
if i < numClusters
for t = 0.1:0.1:0.9
X(k,1:3) = Centers(i,1:3) + (Centers(i+1,1:3)-Centers(i,1:3))*t;
ColorVector(k) = 0;
k = k+1;
end;
end;
end;
handles.X = X;
handles.ColorVector = ColorVector;
updateString{1} = '3D Clusters example loaded.';
case 7 % Toroidal Helix by Coifman & Lafon
noiseSigma=0.05; %noise parameter
t = (1:N)'/N;
t = t.^(ExParam)*2*pi;
handles.X = [(2+cos(8*t)).*cos(t) (2+cos(8*t)).*sin(t) sin(8*t)]+noiseSigma*randn(N,3);
handles.ColorVector = t;
updateString{1} = 'Toroidal Helix example loaded.';
case 8 % Gaussian randomly sampled
X = ExParam * randn(N,3);
X(:,3) = 1 / (ExParam^2 * 2 * pi) * exp ( (-X(:,1).^2 - X(:,2).^2) / (2*ExParam^2) );
handles.X = X;
handles.ColorVector = X(:,3);
updateString{1} = 'Gaussian example loaded.';
case 9 % Occluded disks
m = 20; % Image size m x m.
Rd = 3; % Disk radius.
Center = (m+1)/2;
u0 = zeros(m,m);
for i = 1:m
for j = 1:m
if (Center - i)^2 + (Center - j)^2 < ExParam^2
u0(i,j) = 1;
end;
end;
end;
for diskNum = 1:N
DiskX(diskNum) = (m-1)*rand+1;
DiskY(diskNum) = (m-1)*rand+1;
u = u0;
for i = 1:m
for j = 1:m
if (DiskY(diskNum) - i)^2 + (DiskX(diskNum) - j)^2 < Rd^2
u(i,j) = 1;
end;
end;
end;
X(diskNum,:) = reshape(u,1,m*m);
end;
% Since this is a special manifold, plot separately.
axes(handles.maniAXES);
t = 0:0.1:2*pi+0.1;
plot(ExParam*cos(t)+Center,ExParam*sin(t)+Center);
axis([0.5 m+0.5 0.5 m+0.5]);
hold on;
handles.ColorVector = (sqrt((DiskX-Center).^2+(DiskY-Center).^2))';
scatter(DiskX,DiskY,12,handles.ColorVector');
hold off;
handles.X = X;
updateString{1} = 'Occluded Disks example loaded.';
updateString{3} = 'Warning: Embedding may be slow.';
case 10 % Swiss Roll
tt = (rand(1,N)*3-2)*pi;
height = 5*rand(1,N);
handles.X = [cos(tt); height; (sin(tt)-1).*sign(pi/2-tt)]';
handles.ColorVector = tt';
updateString{1} = 'Sigma example loaded.';
end;
assignin ('base','maniX',handles.X);
updateString{2} = 'Manifold data written to matrix "maniX"';
set(handles.UpdatesText,'String',updateString);
handles.isExample = 1;
guidata(hObject, handles);
if exampleValue ~= 9 % Already plotted Occluded Disks example.
PlotManifold(hObject,eventdata,handles,0);
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -