フィルターのクリア

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 Center および File ExchangeFile Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by