Crowley
Crowley

Reputation: 2331

Loading multiple files into cell array

Suppose we have directory containing structured data files (text files containing matrix of numbers only).

Is it possible to load them all, no matter what filename they have, into cell array of matrices?

Upvotes: 0

Views: 155

Answers (1)

Shai
Shai

Reputation: 114936

use dir to get all the files in a directory:

fls = dir( fullfile( myFolder, '*.txt' ) );
n = numel(fls);
data = cell(1,n); % preallocate
fot ii=1:n
    data{ii} = dlmread( fullfile( myFolder, fls(ii).name ) ); % read the file using importdata/dlmread/load - whatever works for you
end

Upvotes: 1

Related Questions