I have two column vectors (nx1), and I need to concatenate them together end to end, to end up with another column vector that will be, let's say, (2n,1) size. I tried to use "cat" function like this:
cat(2,a,b)
Where "a" and "b" are column vectors, but it doesn't work as I was expecting, the same way it works when "a" and "b" are arrays: a=[1 2 3] and b=[4 5 6] for example. Is there a way to accomplish that?

 採用された回答

the cyclist
the cyclist 2021 年 3 月 18 日
編集済み: the cyclist 2021 年 3 月 18 日

0 投票

It seems that you just got the dimension wrong. Down the column is dimension 1:
a = [2; 3; 5]; % col vector
b = [7; 11; 13]; % another col vector
c = cat(1,a,b) % concatenate vertically
c = 6×1
2 3 5 7 11 13
d = [a; b] % Another way to concatenate vertically
d = 6×1
2 3 5 7 11 13

1 件のコメント

Larissa Rocha
Larissa Rocha 2021 年 3 月 18 日
Yes, that works too, thank you!

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

その他の回答 (1 件)

Larissa Rocha
Larissa Rocha 2021 年 3 月 18 日

0 投票

I figured out that by using "vertcat" function I get the results wanted to. I'm not deleting the question in case it's another person's doubt too, this is what I did:
a = zeros(3,1)
b = ones(3,1)
c = vertcat(a,b)
%the result is c = (0,0,0,1,1,1) in one column

カテゴリ

ヘルプ センター および 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