Borrar filtros
Borrar filtros

Vectors must be the same length.

387 visualizaciones (últimos 30 días)
Nasser Aljadeed
Nasser Aljadeed el 23 de Sept. de 2015
Editada: Image Analyst el 3 de Abr. de 2021
Every time I run this code, I get "Error using plot Vectors must be the same length.
Error in ex (line 24) plot(t,abs(Y)) "
Here is my code:
clear
dt = 1/100000;
tstart = 0;
tend = 0.020;
t=[tstart : dt : tend];
xc=25*sin(2*pi*150*t)-15*cos(2*pi*800*t);
T = 0.00025;
n = [tstart/T : tend/T];
x1=25*sin(2*pi*150*n*T)-15*cos(2*pi*800*n*T);
% Quantize Signal
x2=fix(x1);
% Define filter coefficents
A = [1];
B = [1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16];
% Filter the quantize signal
Y = filter(B,A,x2);
figure(1)
subplot(211)
plot(t,abs(Y))
xlabel('Frequency (rad/sec)')
ylabel('Magntidue')
subplot(212)
plot(t,angle(Y))
xlabel('Frequency (rad/sec)')
ylabel('Phase')

Respuestas (2)

the cyclist
the cyclist el 23 de Sept. de 2015
The proximate cause of your problem is that you are trying to make an X-Y plot, where X (your variable "t") has 2001 elements, and Y has 81 elements. So, MATLAB cannot figure out how plot each (X,Y) pair, because the two vectors do not have an equal number of points.
It is not easy for me to figure out what you intended to do.
  2 comentarios
Nasser Aljadeed
Nasser Aljadeed el 23 de Sept. de 2015
How can I make these vectors have the same dimensions?
So : t =[tstart : dt : tend] has to have the same dimensions as n = [tstart/T : tend/T]?
the cyclist
the cyclist el 24 de Sept. de 2015
Editada: the cyclist el 24 de Sept. de 2015
Probably the easiest way to ensure an equal number of elements, and uniform spacing, is to use the linspace command to create both vectors.

Iniciar sesión para comentar.


Jae Song
Jae Song el 23 de Sept. de 2015
Editada: Jae Song el 23 de Sept. de 2015
It looks like the variables xc and t have same size. So if you let x2 = fix(xc) instead of x2 = fix(x1). The plot should work. (I don't know that was your intention or not)
clear
dt = 1/100000;
tstart = 0;
tend = 0.020;
t=[tstart : dt : tend];
xc=25*sin(2*pi*150*t)-15*cos(2*pi*800*t);
T = 0.00025;
n = [tstart/T : tend/T];
x1=25*sin(2*pi*150*n*T)-15*cos(2*pi*800*n*T);
% Quantize Signal
x2=fix(xc);
% Define filter coefficents
A = [1];
B = [1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16];
% Filter the quantize signal
Y = filter(B,A,x2);
figure(1);
subplot(211);
plot(t,abs(Y))
xlabel('Frequency (rad/sec)')
ylabel('Magntidue')
subplot(212)
plot(t,angle(Y))
xlabel('Frequency (rad/sec)')
ylabel('Phase')
  2 comentarios
saurabh jain
saurabh jain el 3 de Abr. de 2021
Editada: saurabh jain el 3 de Abr. de 2021
can u help me in this code
Image Analyst
Image Analyst el 3 de Abr. de 2021
Editada: Image Analyst el 3 de Abr. de 2021
@saurabh jain, probably not since @Jae Song was last here in 2015. But you might read this:
and then post your code (not an image of your code) in a new question so people can fix it.

Iniciar sesión para comentar.

Categorías

Más información sobre Single-Rate Filters en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by