Variables Calculated in Function Somehow Aren't Assigned to Output
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Dominic Troche
el 21 de Jul. de 2021
Editada: Dominic Troche
el 21 de Jul. de 2021
My code was working only a day ago, but it just stopped giving me output. I know it calculates the variables I need (wg,pm) becasue it will display them, but it never leaves the scope of the for loop. I know its gotta be something simple, but I'm stumped.
function[wp,pm,wg,gm] = pleaseWork(tf_in)
tf = inline(tf_in,'r')
figure
j = 1
for w = 0:0.1:100
magDB = 20*log10(abs(tf(i*w)));
phase = mod((180/pi)*atan2(imag(tf(i*w)),real(tf(i*w))),-360);
if round(magDB) == 0
wg = w
pm = phase + 180
end
if round(phase) == -180
wp = w
gm = -magDB
end
hold on
subplot(2,1,1)
title('HW 2 #9')
ylabel('Magnitude (dB)')
semilogx(w,20*log10(abs(tf(i*w))),'b.')
hold on
subplot(2,1,2)
ylabel('Phase (deg)')
xlabel('Angular Frequency (rad/s)')
semilogx(w,phase,'b.')
j = j + 1;
end
end
2 comentarios
Torsten
el 21 de Jul. de 2021
Before entering the for-loop, assign values to wg,pm,wp,gm (e.g. NaN).
What's the relevance of the variable j ?
Respuesta aceptada
Más respuestas (0)
Ver también
Categorías
Más información sobre Annotations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!