What does "Vectors must be the same lengths." mean?
Mostrar comentarios más antiguos
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)
Respuesta aceptada
Más respuestas (1)
Chad Greene
el 5 de Sept. de 2014
2 votos
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 comentarios
Mehdi Fazilat
el 17 de Mzo. de 2021
Excellent, how we can make the same two different dimension variables? for example t=101 and E=102
Walter Roberson
el 17 de Mzo. de 2021
L = min(length(t), length(E));
plot(t(1:L), E(1:L))
Categorías
Más información sobre Hilbert and Walsh-Hadamard Transforms en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!