What does "Vectors must be the same lengths." mean?
이전 댓글 표시
I have been trying to adjust the code to have different values but it keeps messing up and I can't get anything to work. Here was the code:
clear; load testtrace.mat
subplot(2,1,1);
plot(t,tracefar)
title('1000 m offset');xlabel('seconds')
subplot(2,1,2);
plot(t,tracenear)
title('10 m offset');xlabel('seconds')
envfar = abs(hilbert(tracefar)); %compute Hilbert envelope
envnear = abs(hilbert(tracenear)); %compute Hilbert envelope
envdbfar=todb(envfar,max(envnear)); %decibel conversion
envdbnear=todb(envnear); %decibel conversion
figure
plot(t,[envdbfar envdbnear],'b');xlabel('seconds');ylabel('decibels');
grid;axis([0 3 -140 0])
and here is the error code that shows up:
>> Untitled2
Error using plot
Vectors must be the same lengths.
Error in Untitled2 (line 3)
plot(t,tracefar)
채택된 답변
추가 답변 (1개)
Chad Greene
2014년 9월 5일
2 개 추천
I'm guessing that there's a variable in testtrace.mat called t, and another variable called tracefar. If you type length(t) into the command window, and then type length(tracefar) into the command window, you'll see that they are different numbers.
When you tell matlab to plot t and tracefar, Matlab needs to plot one y value (tracefar) for each x value (t). If x and y (or t and tracefar) do not have the same number of values, Matlab will get confused.
댓글 수: 2
Mehdi Fazilat
2021년 3월 17일
Excellent, how we can make the same two different dimension variables? for example t=101 and E=102
Walter Roberson
2021년 3월 17일
L = min(length(t), length(E));
plot(t(1:L), E(1:L))
카테고리
도움말 센터 및 File Exchange에서 Hilbert and Walsh-Hadamard Transforms에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!