Using concatenate in vectors

1 回表示 (過去 30 日間)
James Chang
James Chang 2016 年 12 月 12 日
コメント済み: Guillaume 2016 年 12 月 13 日
Create a row vector consisting of the whole numbers (integers) from 1 to 5 and a second row vector consisting of the c = cat(2,x,y) whole numbers 6 to 8. Concatenate these two row vectors into one long row vector using two different methods: square brackets the function cat Create the transpose of each of the two component row vectors that you created in step 1. Concatenate these two column vectors into one long column vector using two different methods: square brackets the function cat
My Code:
x = [1:5] % rows
y = [6:8] % cols
c = cat(2,x,y) % for the rows
z = cat(1,x,y) % for the cols
q = x'; % transpose x
b = y'; % transpose y
How will cat this into one long row and colunm
  2 件のコメント
Jan
Jan 2016 年 12 月 13 日
The first sentence is not clear: "a second row vector consisting of the c = cat(2,x,y) whole numbers 6 to 8"??
Guillaume
Guillaume 2016 年 12 月 13 日
The comment on the line
y = [6:8] % cols
is extremely misleading. y is not a column vector.
It's not clear what difficulty you're having with this very easy problem. Your last sentence does not make sense.

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

採用された回答

Jan
Jan 2016 年 12 月 13 日
  1. You do not need square brackets, because 1:5 is a vector already.
  2. In y = [6:8] % cols the term "cols" is misleading. This is a row vector.
  3. z = cat(1,x,y) % for the cols should produce an error message. Reading it should reveal the problem. You need to transpose both inputs here.
  4. Then you have the code for cat() already. Now try it with the brackets. All you need is [, ] and a "," or ";" as explained in the documentation. Note that the inputs must be transposed here also.
Hint: read the help text of cat.

その他の回答 (0 件)

カテゴリ

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