?? test1.m
字號:
h = figure;
axis([0 10 0 10])
hold on
button = 1;
n = 0;
xy_org = [];
while button == 1 % 輸入數據點,以右鍵作結
[xi,yi,button] = ginput(1);
plot(xi, yi, 'r+');
n = n + 1;
xy_org(:,n) = [xi;yi];
end
pause;% 輸入完畢后按任意鍵繼續
button = 1;
m = 0;
s = zeros(1,2);
pre_m = 0;
while button == 1 % 選擇數據點,以右鍵作結
while button == 1 && m < 2
[xi,yi,button] = ginput(1);
[d, ind] = min(sum((repmat([xi;yi],1,n) - xy_org).^2)); % 求各數據點與當前鼠標點的最小距離
if d <= 0.1
if pre_m ~= 0 % 之前畫過直線,要刷新一下屏幕
plot(xy_org(1,s(:)), xy_org(2,s(:)), 'wo');
plot(xy_org(1,s(:)), xy_org(2,s(:)), 'w');
plot(xy_org(1,s(:)), xy_org(2,s(:)), 'r+');
pre_m = 0;
end
plot(xy_org(1,ind), xy_org(2,ind), 'bo');
m = m + 1;
s(m) = ind;
end
end
if m == 1
plot(xy_org(1,s(m)), xy_org(2,s(m)), 'wo');
plot(xy_org(1,s(m)), xy_org(2,s(m)), 'r+');
elseif m == 2
plot(xy_org(1,s(:)),xy_org(2,s(:)), 'g');
end
pre_m = m;
m = 0;
end
hold off;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -