Uigetdir to pick multiple directories

108 Ansichten (letzte 30 Tage)
Robbie
Robbie am 25 Nov. 2011
Bearbeitet: Stephen23 am 2 Sep. 2024
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

Antworten (2)

Image Analyst
Image Analyst am 25 Nov. 2011
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 Kommentare
praveen rai
praveen rai am 2 Sep. 2024
%%%%%% 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
Stephen23 am 2 Sep. 2024
Bearbeitet: Stephen23 am 2 Sep. 2024
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.
This line is unlikely to be useful, for reasons that have already been explained here:
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.

Melden Sie sich an, um zu kommentieren.


Robbie
Robbie am 25 Nov. 2011
I found a function on the file exchange that seems to work the way i want it 'uipickfiles' but i am open to other ways how to do this. Thanks

Kategorien

Mehr zu Environment and Settings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by