Passing the listbox name to a function

1 visualización (últimos 30 días)
Jason
Jason el 27 de Feb. de 2017
Comentada: Jason el 27 de Feb. de 2017
Hi, I have a function that updates the files in a directory into a listbox:
% Refresh list Box
fname=get(handles.textSaveFolder,'String');
%List all tif images into the list box.
[pathstr,name,ext] = fileparts(fname)
filePattern = fullfile(pathstr, ['*',ext]);
myFiles = dir(filePattern);
ListOfImageNames = {}; % Initialize
for Index = 1:length(myFiles)
% Get the base filename and extension.
baseFileName = myFiles(Index).name;
[folder, name, extension] = fileparts(baseFileName);
% Examine extensions for ones we want.
extension = upper(extension);
switch lower(extension)
case {'.jpg', '.tif','tiff'}
% Keep only PNG, BMP, JPG, TIF, or AVI image files.
ListOfImageNames = [ListOfImageNames baseFileName];
% otherwise
end
end
% Now we have a list of validated filenames that we want.
% Send the list of validated filenames to the listbox.
set(handles.listbox2, 'string', ListOfImageNames);
drawnow;
To make this a stand alone function I will need to pass in the listbox name, "istbox2" in this case. How can I pass the listbox name as a variable to the function so I can apply to any listbox.
Thanks Jason

Respuesta aceptada

Walter Roberson
Walter Roberson el 27 de Feb. de 2017
You could pass handles.listbox2 (or as appropriate) to the function, which could then set() against the variable that holds that.
Or you could pass a string to the function, such as in the variable BoxName . Then you could
set( handles.(BoxName), ...)

Más respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by