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!