Assembly of matrices using for loop
古いコメントを表示
I have 20 excel files containing matrix, each matrix has 49 columns (all the matrix has the same number of columns) and a variable number of lines (the number of lines is not always the same for all the matrix I have). I want to assemble all of them in one excel file , what makes a new matrix with 49 columns.This should not be addition but assembly. For exemple if I have these two matrix : A = [1 2;3 4] B = [5 6;7 8] The result I wish to have is a new matrix C while : C =
1 2
3 4
5 6
7 8
In other words it is sort of like joining the matrices but by adding each matrix to the previous one, successively from the line where the previous matrix has stopped while keeping the same number of columns (49).
Any idea how to do this? Thanks in advance
2 件のコメント
madhan ravi
2018 年 8 月 31 日
編集済み: madhan ravi
2018 年 8 月 31 日
C=[A;B] this will give the result for the example?
Silver
2018 年 9 月 1 日
採用された回答
その他の回答 (1 件)
Following the examples in the MATLAB documentation:
N = 20;
C = cell(1,N);
for k = 1:N
F = sprintf('file%d.txt', k);
C{k} = importdata(F);
end
out = vertcat(C{:})
Or use dir, as shown in the link I gave above.
8 件のコメント
Silver
2018 年 9 月 1 日
Inside the loop get the required data, e.g.:
N = 20;
C = cell(1,N);
for k = 1:N
F = sprintf('file%d.txt', k);
T = importdata(F);
C{k} = T.data;
end
out = vertcat(C{:})
Remember to accept the answer that helped you most to resolve your original question!
Silver
2018 年 9 月 4 日
Silver
2018 年 9 月 4 日
Extract the required data before putting it in C, something like this:
G{k} = T.textdata(2:end,1);
...
time = vertcat(G{:});
Here is an explanation of why your syntax does not work:
Silver
2018 年 9 月 5 日
Silver
2018 年 9 月 6 日
カテゴリ
ヘルプ センター および File Exchange で Data Import from MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
