Tengo problemas con el comando plot y no sé por qué
20 views (last 30 days)
Show older comments
Quiero graficar una señal seno perfecta, que se vea curvilinea, y por supuesto para eso necesito colocar varios tiempos... y cuando trato de agregarle más tiempos entre medio, me sale error, de que la dimensión del largo del vector debe ser correspondiente, y no entiendo por qué, si mi código no es distinto a otros que he hecho antes.
>> t=0:0.1:10;
%para el v0 en la resistencia:
w=5000/11;
y=1/sqrt(2)*sin(w*t+pi/4);
%para el v0 en el capacitor:
z=1/sqrt(2)*sin(w*t+3*pi/4);
>> plot(t,y)
>> t=0:0.01:10;
>> plot(t,y)
Error using plot
Vectors must be the same length.
>> t=0:0.01:100;
>> plot(t,y)
Error using plot
Vectors must be the same length.
>> t=0:0.1:100;
>> plot(t,y)
Error using plot
Vectors must be the same length.
Por favor, que alguien me diga cómo arreglar esto, gracias.
0 Comments
Answers (1)
Paras Gupta
on 19 Oct 2023
Hi,
I understand that you are getting an error while plotting when you try to change the time range with a smaller step size.
The error occurs because changing the step size of the time values alters the length of the 't' vector, while the 'y' and 'z' vectors remain the same length. This mismatch in vector lengths causes the error.
To resolve this, you need to recalculate the 'y' and 'z' vectors using the updated time values. You can refer to the following code to achieve the same.
t = 0:0.1:10;
w = 5000/11;
y = 1/sqrt(2) * sin(w*t + pi/4);
z = 1/sqrt(2) * sin(w*t + 3*pi/4);
plot(t, y)
% Update time values and recalculate the signals
t_new = 0:0.01:10;
y_new = 1/sqrt(2) * sin(w*t_new + pi/4);
z_new = 1/sqrt(2) * sin(w*t_new + 3*pi/4);
figure % Create a new figure
plot(t_new, y_new)
Hope this answer resolves your query.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!