Using rows of different files to create a matrix
2 ビュー (過去 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)
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
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!