Loading files from the folder

20 visualizaciones (últimos 30 días)
Chris Dan
Chris Dan el 24 de En. de 2020
Comentada: Geoff Hayes el 27 de En. de 2020
Hello,
I have this code which allows the user to select any folder on the computer and then loads all the .mat files to the directory.
%% Data Acuisition from the folder%%%
pathname = uigetdir;
allfiles = dir(fullfile(pathname,'*.mat'));
out = load(allfiles(1).name);
% load all files in a struct so they can accessed later on
for k = 2: numel(allfiles)
out(k) = load(allfiles(k).name);
end
I want to make changes to it such that, user is able to select some files from the folder and not all of them to be loaded to matlab directory..
Does any one know how can we do it ?

Respuesta aceptada

Geoff Hayes
Geoff Hayes el 24 de En. de 2020
Editada: Geoff Hayes el 24 de En. de 2020
hamzah - could you use uigetfile and allow the user to select the files that they are interested in?
[file,path] = uigetfile('*.mat',...
'Select One or More Files', ...
'MultiSelect', 'on');
  7 comentarios
Chris Dan
Chris Dan el 25 de En. de 2020
Okay, Thanks :)
I am trying to make function which I can call any where to open the folder
Will this work?
out = DataLoading(uigetfile);
function [out] = DataLoading(uigetfile)
[files,pathToFiles] = uigetfile('*.mat',...
'Select One or More Files', ...
'MultiSelect', 'on');
out = {};
if ~iscell(files)
out{1} = load(fullfile(pathToFiles, files));
else
for k = 1:length(files)
out{k} = load(fullfile(pathToFiles, files{k}));
end
end
end
Geoff Hayes
Geoff Hayes el 27 de En. de 2020
I don't undertstand the purpose of including the uigetfile in the signature
function [out] = DataLoading(uigetfile)
This input parameter is unnecessary.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by