필터 지우기
필터 지우기

Vectors must be the same length.

조회 수: 387 (최근 30일)
Nasser Aljadeed
Nasser Aljadeed 2015년 9월 23일
편집: Image Analyst 2021년 4월 3일
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')

답변 (2개)

the cyclist
the cyclist 2015년 9월 23일
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
Nasser Aljadeed
Nasser Aljadeed 2015년 9월 23일
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 2015년 9월 24일
편집: the cyclist 2015년 9월 24일
Probably the easiest way to ensure an equal number of elements, and uniform spacing, is to use the linspace command to create both vectors.

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


Jae Song
Jae Song 2015년 9월 23일
편집: Jae Song 2015년 9월 23일
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
saurabh jain
saurabh jain 2021년 4월 3일
편집: saurabh jain 2021년 4월 3일
can u help me in this code
Image Analyst
Image Analyst 2021년 4월 3일
편집: Image Analyst 2021년 4월 3일
@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.

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

카테고리

Help CenterFile Exchange에서 Single-Rate Filters에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by