ListBox callback error

Hi, do not know where I made a mistake? Thank you very much.
??? Undefined variable "handles" or class "handles.ListBox".
Error in ==> dilist> dilist_callback at 23
fname = get (handles.ListBox, 'String');
??? Evaluating Error while uicontrol Callback
function dilist
h1 = figure;
handles.ListBox = uicontrol ('Units', 'Normalized', 'Position', [0.01 0.1 0.1 0.15], ...
'Style', 'List', 'Callback', @ dilist_callback);
P = fileparts (mfilename ('fullpath'));
nfolder uigetdir = (P, 'whatever');
handles.dfolder = nfolder;
dfiles = dir (handles.dfolder);
dfiles dfiles = (3: end);
nfiles = length (dfiles);
nfiles if <1
disp ('no files availabel.')
return;
end
set (handles.ListBox, 'String', char (dfiles.name), 'value', 1);
s = [num2str (nfiles) 'files in:' handles.dfolder];
end
dilist_callback function (src, evt)
fname = get (handles.ListBox, 'String');
fname = fname (get (handles.ListBox, 'value'), :);
dicominfo info = ([handles.dfolder '\' fname]);
Y1 = dicomread (info);
imshow (Y1)
clims = [10 1800];
end

1 comentario

Walter Roberson
Walter Roberson el 11 de Feb. de 2012
duplicate is at http://www.mathworks.com/matlabcentral/answers/28597-help-with-listbox-in-dicom

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 11 de Feb. de 2012

1 voto

After the line
handles.ListBox = [...]
add
guidata(h1, handles);
Change the line
dilist_callback function (src, evt)
to
function dilist_callback (src, evt)
In the line immediately after that add
handles = guidata(ancestor(src),'figure');

2 comentarios

Adam
Adam el 22 de Feb. de 2012
Thank you but now matlab did nothing. Depicted in the figure window which empty listbox.
Tannistha
Tannistha el 23 de Feb. de 2012
try this
set (handles.ListBox, 'String', {dfiles.name}, 'value', 1)

Iniciar sesión para comentar.

Preguntada:

el 11 de Feb. de 2012

Editada:

el 21 de Oct. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by