MATLAB: Inserting contents of text file into a Listbox

insertlistbox

Hello. I have a text file that has a list of images that need processing (crop them and resave). So I am wanting to open the text file, and display the contents (=list of image files to be cropped) into a listbox. I can open the text file OK, but then I can't get its contents into the listbox:
while ischar(tline)
tline = (fgetl(fid1))
set(handles.listbox,'String',{tline})
end
fclose(fid1);
Jason

Best Answer

Hi,
I guess you need this :
% Read the list in the text file "TextFile.txt"
fid = fopen('TextFile.txt','r');
MyList = textscan(fid,'%s','delimiter','\n');
fclose(fid);
% put the list in the listbox
set(handles.listbox1,'String',MyList{:});