Loading any Excel file from a folder
216 views (last 30 days)
For a uni project i need to load any excel file (they all have different names) in my matlab function to analyse them later on.
But i dont know how to exactly load them and get them in my function. Here is what i got so far...
file_type = 'xlsx';
file_array = dir(fullfile(path,strcat('*.',file_type)));
file_folder = file_array(n_file).folder;
file_name = file_array(n_file).name;
file = strcat(file_folder,'\',file_name);
I am pretty new to matlab and would like to get some help from u guys. Thanks for helping me!!
langrg on 4 Feb 2021
The code below should work.
% Find xlsx files
files = dir(fullfile(path, '*.xlsx'));
% Loop on every file found
for idx_file = 1:length(files)
% Read xlsx
[~, ~, rawData] = xlsread(fullfile(path, files(idx_file).name), 'Sheet1'); % 'Sheet1' or the name of the sheet to read
% Write your code after here
I don't know what you need to do after with data you loaded (rawData)...