How can I concatenate two vectors?

2 vues (au cours des 30 derniers jours)
mm99
mm99 le 18 Jan 2020
Commenté : mm99 le 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 commentaires
Robert U
Robert U le 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 le 19 Jan 2020
corrected!

Connectez-vous pour commenter.

Réponses (1)

Turlough Hughes
Turlough Hughes le 19 Jan 2020
Modifié(e) : Turlough Hughes le 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 commentaires
Turlough Hughes
Turlough Hughes le 19 Jan 2020
Ok, I see what you are asking.
v = zeros(1,iterations);
v(1:numel(signal))=signal;
mm99
mm99 le 19 Jan 2020
thanks a lot!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by