Merge two vectors into matrix

I have a time vector of 1x1024 double and an amplitude vector of 1024x1 double. How do I combine these vectors into a single matrix?

Antworten (3)

Andrei Bobrov
Andrei Bobrov am 7 Feb. 2018

14 Stimmen

your_matrix = [vector1(:), vector2(:)];
Idan Cohen
Idan Cohen am 22 Apr. 2020

1 Stimme

Hi,
I have a similar question. I have three vectors - X, Y and Z.
How can I merge these vectors into on matris so I can plot 3-D surf graph?
Thanks.
Von Duesenberg
Von Duesenberg am 21 Jan. 2017

0 Stimmen

Something like this?
vector1 = rand(1024,1);
vector2 = rand(1, 1024);
newVector = [vector1 vector2'];

3 Kommentare

Guillaume
Guillaume am 21 Jan. 2017
Bearbeitet: Guillaume am 21 Jan. 2017
newVector is a misnomer. The result is a matrix.
>>isvector(newVector)
ans =
false !
Not knowing the values in vector2 it would be safer to use vector2.' instead of vector', in case there are complex values.
Von Duesenberg
Von Duesenberg am 21 Jan. 2017
You're right, Guillaume. Thanks for this.
Mohammed Ayoub
Mohammed Ayoub am 7 Feb. 2018
Use "horzcat" command after transposing one of the vector. The result will be horizontally concatenates arrays. Thanks

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrices and Arrays finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 21 Jan. 2017

Beantwortet:

am 22 Apr. 2020

Community Treasure Hunt

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

Start Hunting!

Translated by