Borrar filtros
Borrar filtros

Add Item to my listbox in GUI ?!

3 visualizaciones (últimos 30 días)
Maryam Emad
Maryam Emad el 5 de Dic. de 2011
Welcome All '
I hope to be Alright :)
I have listbox in my GUI , and Add pushbutton, any time when user want to add item in listbox he click on it and brows to chose file he want.
My Question is how i can handle (deal) with this item that user add it. note that the kind of this item is file with the extension .m
Also , I want to put this new item (ie.file) in the same folder that contain my code.
In Add callback function i do like this:
[filename, pathname] = uigetfile( ... {'*.m', 'All matlab-Files (.m)'; ... '.*','All Files (.)'}, ... 'Select Matlab File');
%if file selection is cancelled, pathname should be zero %and nothing should happen
if pathname == 0
return
end
%gets the current data file names inside the listbox
inputFileNames = get(handles.listbox2,'String');
%if they only select one file, then the data will not be a cell %if more than one file selected at once, %then the data is stored inside a cell
if iscell(filename) == 0
%add the most recent data file selected to the cell containing
%all the data file names
inputFileNames{end+1} = filename;
%else, data will be in cell format
else
%stores full file path into inputFileNames
for n = 1:length(filename)
%notice the use of {}, because we are dealing with a cell here!
inputFileNames{end+1} = filename{n};
end
end
%updates the gui to display all filenames in the listbox
set(handles.listbox2,'String',inputFileNames);
Tq.

Respuestas (1)

Fangjun Jiang
Fangjun Jiang el 5 de Dic. de 2011
When filename is a cell array
inputFileNames = [inputFileNames; filename];

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by