listbox, get items below selection

1 view (last 30 days)
Hi. I have a listbox containing about 40 image filenames.
I want to select one (I do this using the mouse), and then take that one and the 5 filename below it and process them.
This is my code:
Selected = get(handles.listbox1, 'value')
for n = Selected:Selected+6
tilect=1
baseImageFileName = strcat(cell2mat(ListOfImageNames(n)))
fullImageFileName = [folder '\' baseImageFileName]; % Prepend folder.
file=fullImageFileName
setappdata(0,'filename',file); % Save for later
IM = imread(file);
figure(findobj('Name','Tiles')) %plot to figure already open
subplot(1,6,tilect)
tilect=tilect+1;
end
But its giving me an error
Undefined function or variable "ListOfImageNames".

Accepted Answer

Image Analyst
Image Analyst on 13 Oct 2014
You need to load the image names into the cell array before you go into the loop:
ListOfImageNames = get(handles.listbox1, 'String');
Then in the loop I think you can just extract the string:
baseImageFileName = ListOfImageNames{n};
fullImageFileName = fullfile(folder, baseImageFileName); % Prepend folder.
  3 Comments
Jason
Jason on 13 Oct 2014
thanks. I have to use tilect as sometimes the image I select is say 5th in the list, so my index n is from 5 to 11.
J
Image Analyst
Image Analyst on 13 Oct 2014
Oh, okay, right. Just don't set tilect = 1 at the top inside of the loop or it will never change.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!