Using rows of different files to create a matrix
Afficher commentaires plus anciens
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 commentaire
Bob Thompson
le 27 Fév 2018
What type of files?
Réponses (1)
Jos (10584)
le 27 Fév 2018
% 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
Catégories
En savoir plus sur Cell Arrays dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!