I have array with different length I would put them in one matrix

3 ビュー (過去 30 日間)
Willim
Willim 2019 年 3 月 14 日
コメント済み: Cam Salzberger 2019 年 3 月 14 日
I have different length arrays such as
t1=[1 2 1 2 3 4];
t2=[2 4 5 5 2 2 434 3 4 32 3 2];
t3= [3 4 5 2 1 1 1 2 3 4 4 4 44 5 5 5 6 3];
I would put them in one matrix as
t= [t1;t2;t3]
Is there anyway to do it ?
  1 件のコメント
Cam Salzberger
Cam Salzberger 2019 年 3 月 14 日
Two questions to clarify:
  1. Why do you need these to all be in a single numeric matrix? What is it going to be used for after this?
  2. If you do get them in one numeric matrix, would you accept padding the vectors with zeroes or NaNs or some other "fill-in" value?

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

回答 (1 件)

Adam
Adam 2019 年 3 月 14 日
編集済み: Adam 2019 年 3 月 14 日
t = [t1, t2, t3];
will concatenate them. Obviously you can't put them together as individual columns or rows in a numeric matrix if they are different length unless you want to pad with 0s or NaNs or use a cell array (which is always a last resort)
  2 件のコメント
Willim
Willim 2019 年 3 月 14 日
Thank you I need them as seprate columns
madhan ravi
madhan ravi 2019 年 3 月 14 日

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

カテゴリ

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