필터 지우기
필터 지우기

Automatically upload a folder of files into a listBox

조회 수: 1 (최근 30일)
Emanuele Gandola
Emanuele Gandola 2015년 10월 6일
댓글: Emanuele Gandola 2015년 10월 6일
Hallo! I'd like to allow the GUI user to automatically select all .jpg file from a folder. I have been implemented a checkbox called check_Folder, if it is checked I'd like to upload into the listbox1 all the jpeg files that are into the folder in which is the one selected.
in the else case it works perfectlly
I've been implemented this if routine
-
[filenamesCell, pathname] = uigetfile({'*.jpg'},'Select file(s)','MultiSelect');
if get(handles.check_Folder , 'Value') == true
lista = dir ('pathname*.jpg');
for i = 1: length(lista)
oldlist = cellstr( get(handles.listbox1, 'String') );
filenamesCell = lista(i,1).name
set(handles.listbox1, 'String', [oldlist; fullfile(pathname, filenamesCell)]);
end
else
if ~isnumeric(filenamesCell)
oldlist = cellstr( get(handles.listbox1, 'String') );
set(handles.listbox1, 'String', [oldlist; fullfile(pathname, filenamesCell)]);
end
end
I've check into the command window that
lista = dir ('pathname*.jpg');
and
filenamesCell = lista(i,1).name;
works, but into the GUI nothing happends. And at the end I'd like to give in input (Through an execute Push_button) the list generated into the ListBox to a main fuction to elaborate the images all toghether.
Thanks 2000 times for your help

채택된 답변

Image Analyst
Image Analyst 2015년 10월 6일
In the click callback event for your listbox, have this:
% Get a list of indexes in the listbox that the user has selected.
Selected = get(handles.listbox1, 'value');
% If more than one is selected, bail out. OPTIONAL. DELETE IF YOU WANT TO ALLOW MULTIPLE SELECTIONS.
if length(Selected) > 1
return;
end
% If you get to here, exactly 1 is selected.
% Get a list of all the items in the listbox.
ListOfImageNames = get(handles.listbox1, 'string');
% Get the name(s) of the particular file(s) that has (have) been selected.
imageName = strcat(cell2mat(ListOfImageNames(Selected)));
  댓글 수: 1
Image Analyst
Image Analyst 2015년 10월 6일
Actually you can call that code anywhere, like in the callback of a "Go!" button that will batch process the images.
Perhaps you'd like to look at MAGIC GUI: http://www.mathworks.com/matlabcentral/fileexchange/24224

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Adam
Adam 2015년 10월 6일
편집: Adam 2015년 10월 6일
get(handles.check_Folder , 'Value') == true
will not work as you want. A checkbox value is a double so you would need to do:
logical( get(handles.check_Folder , 'Value') ) == true
to get into your if statement with the correct condition.
if get(handles.check_Folder , 'Value')
...
end
should work too based on implicit conversion of the double to a logical.
This is an annoying effect of all ui components being the same uicontrol class rather than specific ones, so you end up with text controls having a SliderStep too!
  댓글 수: 3
Adam
Adam 2015년 10월 6일
편집: Adam 2015년 10월 6일
Ah yes, that is true actually for 0 and 1. I just happened to test with '3' as my double instead of '1' and unlike in usual logical conditions where 3 is interpreted as 'true'
3 == true
does not return true. Since a checkbox should always be 1 or 0 though the logic does work I guess.
Emanuele Gandola
Emanuele Gandola 2015년 10월 6일
Thank a lot but of course the if cycle work the same, maybe the problem is in this record
lista = dir ('pathname*.jpg');
if I use the entire directory it works
lista = dir ( 'C:\Users\Emanuele\Documents\Dottorato\Sviluppo interfaccia\Caprarola 9-01-2015\*.jpg');

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by