How can I concatenate two vectors?

1 visualización (últimos 30 días)
mm99
mm99 el 18 de En. de 2020
Comentada: mm99 el 19 de En. de 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 comentarios
Robert U
Robert U el 18 de En. de 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 el 19 de En. de 2020
corrected!

Iniciar sesión para comentar.

Respuestas (1)

Turlough Hughes
Turlough Hughes el 19 de En. de 2020
Editada: Turlough Hughes el 19 de En. de 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 comentarios
Turlough Hughes
Turlough Hughes el 19 de En. de 2020
Ok, I see what you are asking.
v = zeros(1,iterations);
v(1:numel(signal))=signal;
mm99
mm99 el 19 de En. de 2020
thanks a lot!

Iniciar sesión para comentar.

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by