How to use a push button to go to the next image in a listbox GUI

조회 수: 2 (최근 30일)
Hello,
I have tried and tried and cannot get my piece of code to work, I know I'm lacking somewhat in knowledge. I am trying to go to the next value in the list box using the 'value' I know it might seem a bit pointless as I have the list box already that I can cycle through the images with but for the purpose of image processing this will make it easier to analyze each image,
function pushbutton3_Callback(hObject, eventdata, handles)
handles.output = hObject;
picfromlist = get(handles.listbox1,'value');
nextpic = picfromlist + 1;
buttonpress(hObject, eventdata, handles);
imshow(nextpic(handles.listbox1,'value'));
guidata(hObject, handles);
The error I get is.
Subscript indices must either be real positive integers or logicals.
Error in Groundtruth>pushbutton3_Callback (line 124)
imshow(nextpic(handles.listbox1,'value'));
Thanks!

채택된 답변

Image Analyst
Image Analyst 2014년 11월 28일
To get it to "keep going", you will need to update the listbox value with the index that you just displayed. Starting with the code in my comment, add this:
if nextpic > length(MyListOfImages)
nextpic = MyListOfImages;
end
imshow(MyListOfImages{nextpic});
set(handles.listbox1,'Value', nextpic); % Update selection in listbox.
Since the selected item has been updated, the next time you push the button it will start with this updated value and do what you want. (The user can also override that by selecting a different item in the listbox, if they want, and it will use the item after that the next time they push the button.)

추가 답변 (1개)

Orion
Orion 2014년 11월 27일
Hi,
For what I see,
picfromlist = get(handles.listbox1,'value');
=> picfromlist is an integer or a vector of integer.
nextpic = picfromlist + 1;
=> nextpic is an integer or a vector of integer.
then you try
imshow(nextpic(handles.listbox1,'value'));
nextpic(handles.listbox1,'value') has no sense.
I don't kwowwhat is your list, but I guess you wanna do something like :
function pushbutton3_Callback(hObject, eventdata, handles)
handles.output = hObject;
picfromlist = get(handles.listbox1,'value');
nextpic = picfromlist + 1;
buttonpress(hObject, eventdata, handles);
MyListOfImages = get(handles.listbox1,'String');
imshow(MyListOfImages{nextpic});
guidata(hObject, handles);
  댓글 수: 2
Image Analyst
Image Analyst 2014년 11월 27일
Don't forget to check that nextpic is not greater than the number of items in the listbox:
if nextpic > length(MyListOfImages)
nextpic = MyListOfImages;
end
imshow(MyListOfImages{nextpic});
Mauricio Ramirez
Mauricio Ramirez 2014년 11월 28일
Thanks for that, its working better but still not exactly as I would want it too. Its showing the next picture/file but I want it to keep going showing the next 1, 2, 3, 4, ... n photos any ideas? I tried a couple of things but neither worked.
Thanks Image Analyst I almost forgot to stick that in.

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

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by