MATLAB: Load matrices from .txt files from directory

arrayloadmatricesmatrixtxt

Hello, I need to load 24 matrices (6 columns by n rows) from .txt files. They consist of 31 lines of text and I need only matrices of doubles (get rid of text). I tried to load them from directory (C:\Users\pawel\Desktop\Jump), but I cant do it. I'd like to get 24 loaded matrices that (preferably) are named just like files that I load, I don't know is it possible to do (I think it would be nice to create some struct (testsample) that contains these matrices but it's way too much to ask) Could you help me?

Best Answer

SOLVED

% Read all file names from dir, need it for /path to load.
files = dir('*.txt');
% Create Sample doulbe 3D XXX size ((size(files), 1)), 7200, 6)
%THIS IS MY EXAMPLE MATRIX
Sample = zeros(size((files), 1), 7200, 6);
% Flling up the Sample based on files in dir. 
for i = 1:size((files), 1)
A = readtable(files(i).name);
Sample(i,:,:) = table2array(A(:,1:6));  
clear i; clear A;
end

I can't see the option to close the topi if it's solved.

Related Question