Vectors Must be same length. Do I use Linspace or ?

18 visualizaciones (últimos 30 días)
Zack Hawkins
Zack Hawkins el 6 de Abr. de 2021
Comentada: VBBV el 7 de Abr. de 2021
I am not sure if I am supposed to be using linspace or not to ensure that vectors are the same length.
Vectors must be the same length is the error I cannot figure out. Here is the code(A picture is also provided that looks much more readable)
CODE STARTS BELOW:
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
clc
clear
close all
k = input('Enter the value of gain k = '); % (gain k = 9 is given in the que.)
wn = input('Enter the value of natural Frequency wn = '); % (natural frequency wn = 3 is given in the que)
% step response & pole plot for zeta = 3
zeta = 3;
num = [k*wn^2];
den = [1 6*zeta wn^2];
sys = tf(num,den);
%[y,t] = step(sys);
k= 9;
s= 0.1:0.1:2;
w= 3;
tiledlayout(1,2);
ax1 = nexttile;
ax2 = nexttile;
for i = 1:length(s)
y = stepResponse(k, s(i), w);
t = 0:0.05:6;
plot(ax1, t, y)
xlabel (ax1, 'Time (sec)'); ylabel(ax1, 'Amplitude');
title(ax1, 'Step Reponse');
all_roots = getPoles(k, s(i), w);
plot (ax2, all_roots(:, 1), all_roots(:, 2), 'o');
xlabel (ax2, 'Real Part'); ylabel(ax2, 'Imaginary Part');
title(ax2, 'Pole Locations in Complex Plane');
hold(ax2, 'on');
pause(0.25);
end
function y=stepResponse(a, b, c)
y=step(a, b, c);
end

Respuesta aceptada

VBBV
VBBV el 6 de Abr. de 2021
%if true
t = linspace(0,6,length(s));%0:0.05:6;
What is size of variable s in workspace ?
  7 comentarios
Zack Hawkins
Zack Hawkins el 7 de Abr. de 2021
Error: Unable to perform assignment bc the indices on the left are not compatible with the size of the right side.
Did i place the code in the correct place? (2 pics below showing different placements of the code you provided). I get the same error in both cases.
I also tried doing this placement incase I misunderstood you:
I really appreciate the help. I just had a professor yell at me today for not remembering something he mentioned 11 weeks ago. Although it still isnt working yet, you gave me hope :)
VBBV
VBBV el 7 de Abr. de 2021
%f
y = stepResponse(k, s(i), w);
K(i) = y;
plot(ax1,t(1:i),K(1:i))
Ok. In that case output of stepresponse is singular value. So, you can try above

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by