Assembly of matrices using for loop
5 ビュー (過去 30 日間)
古いコメントを表示
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?
採用された回答
James Tursa
2018 年 8 月 31 日
Read each individual file into a cell array element, then vertically concatenate the cells all at once.
2 件のコメント
Stephen23
2018 年 9 月 1 日
編集済み: Stephen23
2018 年 9 月 1 日
@Silver: you do not need to use any loops, as MATLAB's file importing functions are quite capable of importing the entire file by themselves. Also importing the data as character and then using str2double is most likely a misdirection: MATLAB's file importing function already import numeric data as numeric. So none of your code is very useful, or a good way to approach this task. A much better approach is to read the documentation:
and pick a suitable method for reading your files.
"And what about "vertically concatenate the cells all at once" I dont see what that means"
Once you have all of the imported numeric data into one cell array, after the loop you can vertically concatenate the imported data into one matrix, exactly as you requested, e.g.:
mat = vertcat(C{:})
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!