How can I concatenate two vectors?

조회 수: 2 (최근 30일)
mm99
mm99 2020년 1월 18일
댓글: mm99 2020년 1월 19일
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
Robert U
Robert U 2020년 1월 18일
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 2020년 1월 19일
corrected!

댓글을 달려면 로그인하십시오.

답변 (1개)

Turlough Hughes
Turlough Hughes 2020년 1월 19일
편집: Turlough Hughes 2020년 1월 19일
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
Turlough Hughes
Turlough Hughes 2020년 1월 19일
Ok, I see what you are asking.
v = zeros(1,iterations);
v(1:numel(signal))=signal;
mm99
mm99 2020년 1월 19일
thanks a lot!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by