Filter löschen
Filter löschen

How can I concatenate two vectors?

2 Ansichten (letzte 30 Tage)
mm99
mm99 am 18 Jan. 2020
Kommentiert: mm99 am 19 Jan. 2020
Hi ! How can I 'join vector C and signal to get a matrix?
I've tried like this but I dont know if its okay.
Thanks in advance.
f_sine=3e6; % sine frequency [Hz]
T1=1/f_sine; % sine period
n=5; % number of periods
tt=n*T1;
t1 = 0:dt:tt-dt;
burst=sin(2*pi*f_sine*t1);
ww1=hanning(length(burst)/2);
ww=[ww1;zeros(length(burst)/2,1)];
signal=burst.*ww';
iterations=30000;
C = zeros(1, iterations-numel(signal));
v = [signal, C]';
  2 Kommentare
Robert U
Robert U am 18 Jan. 2020
Hi mm99,
your code snippet is not executable. "dt" and "N" are not given. As far as I see, "signal" is a vector whereas "vector" is a matrix. I guess, matrix dimensions and vector do not match, thus joining them is not possible. Provide executable code, and somebody will figure out how to match your variable sizes.
Kind regards,
Robert
mm99
mm99 am 19 Jan. 2020
corrected!

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Turlough Hughes
Turlough Hughes am 19 Jan. 2020
Bearbeitet: Turlough Hughes am 19 Jan. 2020
How can I 'join vector C and signal to get a matrix?
Depends on whether signal is a column vector or row vector
If it's a column vector you probably want to add a column of zeros to the right of signal:
v = [signal zeros( size(signal,1),1 )].' % note the matrix is transposed as you wrote in the original code
If its a row vector you could add zeros below singal as follows:
v = [signal; zeros( 1,size(signal,2) )].'
  3 Kommentare
Turlough Hughes
Turlough Hughes am 19 Jan. 2020
Ok, I see what you are asking.
v = zeros(1,iterations);
v(1:numel(signal))=signal;
mm99
mm99 am 19 Jan. 2020
thanks a lot!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by