Using rows of different files to create a matrix

6 次查看(过去 30 天)
I have 6 separate files all within the workspace each with 3 columns of data with an unknown number of rows but equal for all files. I am trying to use the first row of each file as a line in a new matrix i.e end up with a 6*3 matrix. I want to repeat this for every row until it ends.
So the matrix looks like: row 1 of file 1 row 1 of file 2 row 1 of file 3 row 1 of file 4 row 1 of file 5 row 1 of file 6
Does this make sense? Does anyone know how to do this?

回答(1 个)

Jos (10584)
Jos (10584) 2018-2-27
% Load in the data and store in cells
for k=1:6,
filename = ...
C{k} = MyLoadFile(filename) ; % C{k} is a N-by-3 matrix
end
D = cat(2,C{:}) % D is a N-by-18 matrix, holding all values
% D(k,:) is the data for all first rows of the 6 files
E = arrayfun(@(k) reshape(D(k,:),3,6).', 1:size(D,1),'un',0)
% E{k} holds the requested 6-by-3 matrix for the k-th row

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by