Why are my vectors different lengths?

2 次查看(过去 30 天)
Jesus Marcial
Jesus Marcial 2018-10-2
编辑: Jan 2018-10-2
load 'gong.mat' %Returns sampling frequency Fs and data y
T=1/Fs; %Sampling period
L=1*y; %Number of samples
t=(0:L)*T; %Time vector.
plot(t,y);
I am trying to plot an audio file (gong crash) and am receiving an error in the final line. The error is "Vectors must be the same length." To my understanding, I am compensating for their length by scaling the time vector by dividing by the sampling frequency "Fs."
Thank you for your time and expertise.

回答(2 个)

Stephen23
Stephen23 2018-10-2
t = T*(1:numel(y));

Jan
Jan 2018-10-2
编辑:Jan 2018-10-2
L=1*y; %Number of samples
No. 1*y is the same as y. You did not show how y is defined, by I guess that you want:
L = size(y, 1)
% or
L = size(y, 2)
numel(y) works also, if y is a mono signal, but not for stereo. As Stephen has mentioned already, you have to start at the frame 1, not 0: "1:L" instead of "0:L".

类别

Help CenterFile Exchange 中查找有关 Audio I/O and Waveform Generation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by