MATLAB: Listbox, get items below selection

listboxsubplotvalue

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".

Best Answer

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.