Loop through images in GUI

2 views (last 30 days)
Sophie Lis
Sophie Lis on 13 Jul 2018
Answered: Cris LaPierre on 9 Apr 2019
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 Comment
Adam
Adam on 13 Jul 2018
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.

Sign in to comment.

Answers (1)

Cris LaPierre
Cris LaPierre on 9 Apr 2019
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.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!