Uigetdir to pick multiple directories
101 次查看(过去 30 天)
显示 更早的评论
I was wondering if anyone knows a simple way how to use uigetdir to select multiple directory paths in a similar way to using uigetfile with 'multiselect','on'
Thanks
0 个评论
回答(2 个)
Image Analyst
2011-11-25
Not that I know of with uigetdir. However it could work if you searched your hard drive for directories and then listed them all in a very wide listbox where the user could click on multiple directory names right from the listbox. You could use genpath() to load up the listbox.
18 个评论
praveen rai
2024-9-2
%%%%%% I am using bsig instead of csv%%%
%%%% bsig can be read using data reader
close all;
clear all;
URL = xxxxx;
P = uigetdir(); % PWD is the default
S = dir(fullfile(P,'*','*.bsig'));
%S = dir(fullfile(P,'*','*.bsig','MultiSelect', 'on'));
for k = 1:numel(S)
F = fullfile(S(k).folder,S(k).name);
S(k).data = uigetfile(F);
end
%% check file data
A =[];
B =[];
for i=1:length(S(k).data)
fprintf(['\n ***Reading File_',num2str(i),'_of_',num2str(S(k).data)),'***\n']);
MatfileData=[];
fileName=[S(k).data];
MatfileData=bsigt(fileName);
RootURL = sprintf('%s.XXXX',URL);
A = MatfileData.readGroup(RootURL);
RootURL = sprintf('%s.YYYY',URL);
B = MatfileData.readGroup(RootURL);
for j= 1:length(e_AlnState)
if ((A(j) == 1 ) || (A(j) == 2))
B(i,:) = rad2deg(a_ElEolMeasHistory(:,j));
median_history(i) = median(B(i,:));
end
end
file_name_temp(i,:)= string(theseFiles(i));
azi_val(i) = extractBetween(file_name_temp(i,:),'_azi=' ,'_eli=' );
azi_angles(i) = str2num( azi_val(i));
% elv_val(i) = extractBetween(file_name_temp(i,:),'_eli=' ,'_nrun' );
figure(1)
h1 = plot(B(i,:) , 'DisplayName', strcat("azi =", azi_val(i)) );
hold on
grid on
ylabel('heading)')
xlabel('history (1:10)')
title('variation')
legend
end
Stephen23
2024-9-2
编辑:Stephen23
2024-9-2
For some reason you replaced the file data importing function with UIGETFILE:
S(k).data = uigetfile(F);
Why bother using DIR if you are just going to call UIGETFILE on every single file? It also causes exactly the problem that you described here.
Solution: get rid of UIGETFILE.
for i=1:length(S(k).data)
In my code the DATA field contained the imported file data. Nothing in my code indicates that DATA would contain a filename, so it is unclear where your line of code comes from:
fileName=[S(k).data];
Solution:
- get rid of things in the code that you do not want (e.g. UIGETFILE on every file, which you added to the code).
- write one loop, not two.
- something like this (exactly as I described here):
P = uigetdir(); % PWD is the default
S = dir(fullfile(P,'*','*.bsig')); % or '**' if recursive subfolders
for k = 1:numel(S)
F = fullfile(S(k).folder,S(k).name); % filename
... code that imports data from file F
S(k).data = ... "store" your data here.
end
Or, if you really want to use two loops then go for it. But do not mix up imported data with filenames.
Tip for writing code: do not just write lots and lots and lots of code without testing what it does, otherwise you will have 30/300/3000/... lines of code full of bugs. And no idea how to fix it or where to start debugging. Making lots of random changes is a bad approach to writing and debugging code.
Write one line. Read the documentation for the functions you use on that one line. Test that one line: does it really do what you expect, does it return the data you expect. If you did this, you would not be mixing up file data with filenames, adding 'MultiSelect' to FULLFILE, etc.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!