Error using plot Vectors must be the same length.
이전 댓글 표시
good evening family I was calculating the autocorrelation of the function cos (wt) but every time I compile I get an error like Error using plot Vectors must be the same length.
Help me please.
this is my code :
function autocorrx
f0=20; N=1000 ;
k=5; Tmax=k/f0;
t=0/2:Tmax/N:Tmax;
x=cos(2*pi*f0*t);
subplot(1,1,1);
plot(t,x);
axis([0 0.1 -1 1]);grid;
xlabel('t(s)');
ylabel('cos(wt)');
C = xcorr(x,x)*Tmax;
subplot(2,2,2) ; plot(t,C) ;
axis([-0 0.1 -1 1]);
grid
xlabel ('t') ;
ylabel ('Cxx(t)') ;
title ('autocorrelation ')
end
댓글 수: 5
Adam Danz
2019년 12월 9일
That error means that "Vectors must be the same length". It's pretty clear.
K>> size(t)
ans =
1 1001
K>> size(C)
ans =
1 2001
Clearly t and C and not the same length. So Matlab doesn't know how to pair those coordinates which is required for plotting.
sabayke bremso
2019년 12월 9일
Adam Danz
2019년 12월 9일
Because you're crushing the axis limits.
axis([-0 0.1 -1 1]);
Remove that line.
sabayke bremso
2019년 12월 9일
Adam Danz
2019년 12월 9일
Glad I could help!
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Grid Lines, Tick Values, and Labels에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
