Skip to content

Instantly share code, notes, and snippets.

@kkt-ee
Created September 11, 2020 10:19
Show Gist options
  • Save kkt-ee/8981914cd08558c4170fdf6781a9a591 to your computer and use it in GitHub Desktop.
Save kkt-ee/8981914cd08558c4170fdf6781a9a591 to your computer and use it in GitHub Desktop.
MATLAB read all csv files from a directory (eg. dirx)
%%
pathx = '/root/dirx/'; %---o directory path
files = fullfile(pathx,'*.csv');
d = dir(files); clearvars files
%%
files_with_abs_path = {};
file_name_head ={};
for k=1:numel(d) %---o LOOPING through each filenames
%
files_with_abs_path{k,1} = fullfile(pathx,d(k).name);
file_name_head{k,1}=strtok(d(k).name,'.'); %---o 'strtok'- selects parts of the string(string token); can be useful for creating 'variable name'
end
%
file_name = strcat(file_name_head,'.csv');
%
whos files_with_abs_path file_name_head file_name
clearvars k d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment