Combining Multiple Arrays into One

20 ビュー (過去 30 日間)
Wei Nick Chan
Wei Nick Chan 2016 年 6 月 20 日
コメント済み: Stephen23 2016 年 6 月 20 日
I have multiple arrays with different sizes and I need to combine it into one single array, how do I do that?
A=[1 2 3 4 5]
B=[6 7 8 9]
.
.
.
N=[2 5 6 8 9 4 6]
%after combined
C=[1 2 3 4 5 6 7 8 9 ... N]
%OR
C=[1 2 3 4 5; 6 7 8 9; ... ; N]

回答 (1 件)

KSSV
KSSV 2016 年 6 月 20 日
You can add A, B into one variable using [A B] .
  2 件のコメント
Wei Nick Chan
Wei Nick Chan 2016 年 6 月 20 日
Do I need to type in C=[A B] manually? because I don't know the exact number of arrays I have
Stephen23
Stephen23 2016 年 6 月 20 日
@Wei Nick Chan: you should put all of your arrays into one cell array, then the task of concatenating them together is trivial:
out = cat(2,C{:});
MATLAB can be really fast and simple, when the code is well designed. With lots of separate variables it will be slow and buggy code... read this to know why:

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

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by