Loop through images in GUI

조회 수: 2 (최근 30일)
Sophie Lis
Sophie Lis 2018년 7월 13일
답변: Cris LaPierre 2019년 4월 9일
I have a cell array of images I am trying to loop through in a GUI using a 'NEXT' button, with two images on the screen at the same time. I have 9 images, each three are a series, and I have 3 series', such that I want to view 1 and 2, and 2 and 3, but not 3 and 1, which would be next in the list. I am having trouble coding this, so any help would be very much appreciated!
function next_block_Callback(hObject, eventdata, handles)
handles.curr_im_fig = handles.curr_im_fig+1;
if mod(handles.curr_im_fig,(handles.maxblock))~=0
p1 = handles.curr_im_fig;
p2 = handles.curr_im_fig+1;
else
p1 = handles.curr_im_fig +2;
p2 = handles.curr_im_fig + 3;
end
imshow(handles.images_fig{handles.curr_im_fig},'parent',handles.axes1);
imshow(handles.images_fig{(handles.curr_im_fig)+1},'parent',handles.axes2);
guidata(hObject,handles)
  댓글 수: 1
Adam
Adam 2018년 7월 13일
You don't appear to be using your p1 and p2. I assume these should be in the imshow command instead of the handles.curr_im_fig stuff.

댓글을 달려면 로그인하십시오.

답변 (1개)

Cris LaPierre
Cris LaPierre 2019년 4월 9일
Unsure what is suppose to happen when transitioning 3->4, 6->7, and 9->1, but I'd do something like this
function next_block_Callback(hObject, eventdata, handles)
% if handles.curr_im_fig is 3,6, or 9
if mod(handles.curr_im_fig,3)==0
if handles.curr_im_fig >= 9
% Reset count to 0
handles.curr_im_fig = 0;
end
p1 = handles.curr_im_fig + 1;
p2 = handles.curr_im_fig + 2;
handles.curr_im_fig = handles.curr_im_fig + 2;
else
p1 = handles.curr_im_fig;
p2 = handles.curr_im_fig + 1;
handles.curr_im_fig = handles.curr_im_fig + 1;
end
imshow(handles.images_fig{p1},'parent',handles.axes1);
imshow(handles.images_fig{p2},'parent',handles.axes2);
guidata(hObject,handles)
I'll just caution that I haven't tested this.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by