inserting contents of text file into a Listbox

6 visualizzazioni (ultimi 30 giorni)
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
  3 Commenti
Orion
Orion il 31 Ott 2014
Modificato: Orion il 31 Ott 2014
Note : your method will take more time because you are updating the listbox at every iteration of the loop (long list -> long time), so you just should put the update line outside the loop.
str = [];
i = 0;
while ~feof(fid)
i = i+1;
str{i} = fgetl(fid);
end
set(handles.listbox1,'String',str);

Accedi per commentare.

Risposta accettata

Orion
Orion il 31 Ott 2014
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{:});

Più risposte (0)

Categorie

Scopri di più su Environment and Settings in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by