How to concatenate several matrices into one matrix?

3 ビュー (過去 30 日間)
Negar
Negar 2015 年 1 月 17 日
回答済み: Negar 2015 年 1 月 18 日
Hello all,
I have 3696 matrices with different number of rows but similar number of columns. Is there a way to concatenate them? I know how to do this with two matrices by C = [A B], but what about these many?
Thank you, Negar

採用された回答

Shoaibur Rahman
Shoaibur Rahman 2015 年 1 月 17 日
Perhaps, you mistyped. It is C = [A; B] for different number of rows, but similar number of columns. Anyway, how your matrices are named, like do they have a regular pattern? If I assume that they are named as A1, A2, A3..........A3696, then you can use the following technique:
A1 = rand(3,5); % matrix 1
A2 = rand(2,5); % matrix 2
.
.
. % all other matrices in between
.
.
A3696 = rand(1,5); % matrix 3696
B = [];
for k = 1:3696
m = strcat('A',num2str(k));
B = [B; eval(genvarname(m),'=m')];
end
  1 件のコメント
Shoaibur Rahman
Shoaibur Rahman 2015 年 1 月 17 日
If you have to read matrices from a file, as Image Analyst says below that sounds more reasonable, then it will be easier, but vastly depend on how your data is organized. Very roughly speaking, replace m in this code by the header names (which are supposed to be names of the matrices).

サインインしてコメントする。

その他の回答 (2 件)

Image Analyst
Image Analyst 2015 年 1 月 17 日
It seems doubtful that you'd have 3696 uniquely named variables in your program so I guess you must be planning on retrieving these matrices from files. In that case, use the code in the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F

Negar
Negar 2015 年 1 月 18 日
Hello, sorry for answering so late, my problem is unfortunately more complex than what I had imagined. I'll try to post it again. Thank you for taking the time. Negar

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by