2015-05-02 76 views
0

因此,我有一些代碼曾用於以前版本的Matlab,但現在在R2015a版本中不再適用。Matlab在按下上圖輸入之後不會等待用戶輸入

該代碼允許用戶單擊圖片以獲得所需數量的點的像素座標,然後通過用戶輸入功能,用戶可以給出這些點在世界座標上的世界座標。

事情是,當我按下「Enter」鍵來確認階段的最後一個點時,它會停留在緩衝區,當輸入部分出現時,matlab認爲我按下了輸入而沒有時間給出該座標。

我試着用set(gcf,'CurrentCharacter','char(0))來解決這個問題,但它不起作用。

如果我使用「調試」模式,我停在輸入線:它的工作原理。

npoints = input('How many points do you want to select in the picture ? ') ; 
refpoints = cell(1,npoints); 

for i = 1:npoints % this bit of code allows the user to zoom on a figure, press escape 
% when he's done zooming, click on the desired point and then press enter to confirm 
    fig = figure ; 
    imshow(picture) 
    zoom on; 
    waitfor(gcf,'CurrentCharacter',char(27)); 
    zoom off 
    refpoints{i} = ginput(1); % select point round to the closest pixel 
    waitfor(gcf,'CurrentCharacter',char(13)); 
    close(fig); 
end 

%%%%%%%%%%%%%%%%% 
% Cell2array... % 
%%%%%%%%%%%%%%%%% 

x1 = zeros(npoints,1); % pixel coordinates 
y1 = zeros(npoints,1); 

for k = 1:size(refpoints,2) 
x1(k) = round(refpoints{1,k}(1)); 
y1(k) = round(refpoints{1,k}(2)); 
end 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
% Calculating the world coordinates % 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

disp('Now you need to give the physical coordinates to each of the points specified!') 
disp('-----------------------') 

world = zeros(npoints,2); 
X1 = zeros(npoints,1); % Real world coordinates 
Y1 = zeros(npoints,1); 

fig1 = figure ; 
for jj=1:npoints 
imshow(picture); 
hold on 
plot(x1(jj),y1(jj),'wo'); 
hold off 
world(jj,:) = input('Please enter the world coordinates for the white \n circle marked in the current figure (in square parenthesis): '); 
end 
close(fig1); 

你對如何解決這個問題有什麼想法嗎?

謝謝。

回答

0

沒關係,我用空格鍵代替Enter,它工作正常。