Matlab在按下上图输入之后不会等待用户输入
问题描述:
因此,我有一些代码曾用于以前版本的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);
你对如何解决这个问题有什么想法吗?
谢谢。
答
没关系,我用空格键代替Enter,它工作正常。