KeyPressFcn
每当我获取新数据并绘制它时,我都有一个似乎可以工作的东西。当我没有获得新数据时,KeyPressFcn
似乎不再起作用。但是如果我确实按下了相应的键,一旦我回到数据范围并再次开始获取数据,它就会关闭图形。
我真的很困惑为什么会这样。我的数据收集只有在满足某个条件时才会发生,但是更改KeyPressFcn
andexitflag
是在我的 while 循环内,并且应该在每次循环发生时发生,因此我不明白为什么它不会立即退出我的图。这是代码,
disp('DICOM Slice Viewer');
disp('" ": exit on space key');
global kpressed;
kpressed = 0;
%init figure on screen
global Fig;
Fig=DICOM_SliceViewer_createFigure(1,DICOMparam);
set(Fig.fig,'KeyPressFcn','global kpressed; global Fig; kpressed = get(Fig.fig,''CurrentChar'');');
exitflag = 0;
while (exitflag == 0)
Naviparam=Navi_acquire(Naviparam);
Naviparam=Navi_calc_data(Naviparam);
%calibration calculation !TO BE CHECKED!
DICOMPos = DICOMparam.calib.navi2dicom*[Naviparam.data.Endo_RefOffsetPosVec;1];
ixR=round(min(max(DICOMPos(1),1),DICOMparam.Sx));
iyR=round(min(max(DICOMPos(2),1),DICOMparam.Sy));
izR=round(min(max(DICOMPos(3),1),DICOMparam.Sz));
if kpressed ~= 0
switch kpressed
case ' '
exitflag = 1;
disp('**** Exit DICOM Slice Viewer ****')
end
kpressed = 0;
end
if Naviparam.datastr(5:11)~='MISSING'
%refresh plot with 3 standard cuts
set(Fig.sub1im, 'cdata', reshape(DICOMparam.Vd(ixR,:,:),[DICOMparam.Sy DICOMparam.Sz]));
set(Fig.sub2im, 'cdata', reshape(DICOMparam.Vd(:,iyR,:),[DICOMparam.Sx DICOMparam.Sz]));
set(Fig.sub3im, 'cdata', reshape(DICOMparam.Vd(:,:,izR),[DICOMparam.Sx DICOMparam.Sy]));
drawnow;
end
end
close(Fig.fig);
clear global;