Filter löschen
Filter löschen

Why are my vectors different lengths?

2 Ansichten (letzte 30 Tage)
Jesus Marcial
Jesus Marcial am 2 Okt. 2018
Bearbeitet: Jan am 2 Okt. 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.

Antworten (2)

Stephen23
Stephen23 am 2 Okt. 2018
t = T*(1:numel(y));

Jan
Jan am 2 Okt. 2018
Bearbeitet: Jan am 2 Okt. 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".

Kategorien

Mehr zu Audio I/O and Waveform Generation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by