Azzera filtri
Azzera filtri

Why are my vectors different lengths?

2 visualizzazioni (ultimi 30 giorni)
Jesus Marcial
Jesus Marcial il 2 Ott 2018
Modificato: Jan il 2 Ott 2018
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.

Risposte (2)

Stephen23
Stephen23 il 2 Ott 2018
t = T*(1:numel(y));

Jan
Jan il 2 Ott 2018
Modificato: Jan il 2 Ott 2018
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".

Categorie

Scopri di più su Audio I/O and Waveform Generation in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by