What does "Vectors must be the same lengths." mean?
Ältere Kommentare anzeigen
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)
Akzeptierte Antwort
Weitere Antworten (1)
Chad Greene
am 5 Sep. 2014
2 Stimmen
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 Kommentare
Mehdi Fazilat
am 17 Mär. 2021
Excellent, how we can make the same two different dimension variables? for example t=101 and E=102
Walter Roberson
am 17 Mär. 2021
L = min(length(t), length(E));
plot(t(1:L), E(1:L))
Kategorien
Mehr zu Hilbert and Walsh-Hadamard Transforms finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!