multiple default files for uigetfile

I selected multiple files with uigetfile. later I call uigetfile again and would like to use the previously selected files as defaults, so that I can easily deselect or add files.
Can anybody help me how to have multiple default files?

댓글 수: 5

Mario Malic
Mario Malic 2021년 3월 4일
You can use horzcat or vertcat to concantencate the outputs of your uigetfile, however, you'll need to sort out the thing when the files are from different folder or when they have different number of files, but that's not hard.
I guess I have to change my question. I use uigetfile to select multiple files for evaluation. All of them are in one single folder.
[filenames, pathname] = uigetfile({'*.xls', 'Excel Files (*.xls*)'}, 'Pick your file', 'Multiselect','on', defaultpath);
I select for example file1, file2, and file4. When I reuse uigetfile I'd like these files to be already selected, so that I can easily deselect one of them or add e.g. file5.
In the documentation I found the example for a single default file
[file,path] = uigetfile('*.png','Select an icon file','icon.png')
but could not adapt it to multiple files.
Mario Malic
Mario Malic 2021년 3월 4일
Because such thing is not possible (on MATLAB), as far as I know.
Sorry, Andreas and Mario, did you see my suggestion? It does work as far as I can see.
[file, folder] = uigetfile('*.png','Select an icon file', ...
'"file1.png" "file2.png" "file3.png"')
Mario Malic
Mario Malic 2021년 3월 4일
Yes, it's possible to put it in the uigetfile filter, but when you select another file (with and without Control button), list of files that were in the field are gone.

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

답변 (1개)

Jan
Jan 2021년 3월 4일
편집: Jan 2021년 3월 4일

0 개 추천

Under Windows this works:
% Select multiple M-files:
[File, Folder] = uigetfile('*.m', 'Choose files', '', 'Multiselect', 'on')
% Provide the files as char vector with double quotes aroud the names:
Default = sprintf('"%s" ', File{:});
Default(end) = []; % Remove trailing space, just to be lean
[File2, Folder2] = uigetfile('*.m', 'Choose files', Default, 'Multiselect', 'on')
% Pressing Enter selects the both default files.

댓글 수: 3

thanks, that helped, but not finally
I can select files 1,2 and 3
the second time the correct files are in the File name field, but they are not "selected"
If I then try to add file4 by holding the Ctrl key and select the file it overwrites the previous selection.
Jan
Jan 2021년 3월 5일
I see. You are right: Matlab's call to the file chooser dialog does not select the default file oder files. This is a "feature" of the Java FileChooser dialog, which does not offer a method for an initial selection. See: https://stackoverflow.com/questions/33945713/setselectedfilefile-file-does-not-present-selection-in-gui-of-jfilechooser
thanks anyway

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

카테고리

도움말 센터File Exchange에서 App Building에 대해 자세히 알아보기

제품

릴리스

R2020b

질문:

2021년 3월 4일

댓글:

2021년 3월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by