MATLAB: Help!! I’m trying to plot a function where the output changes with different values of the array. the for loop works, I can see the values changing. I just have trouble with plotting it. I get a graph with nothing in it! any help is appreciated!

arrayiterationplotstep signal

gamma=0.268;
dt=0.05;
T=10;
t=0:dt:T
for tt=0:dt:T
x=gamma*sqrt(((1-cos(0.7255*t)).^2+(sin(0.7255*t)).^2)/((1-gamma*cos(0.7255*t)).^2+(gamma^2)*(sin(0.7255*t)).^2))
y=abs(x)
end
figure;
hold on;
grid on;
plot(t,y);
title('1b)')
xlabel('frequncy (GHz)')
ylabel('|Gamma|')
hold off;

Best Answer

gamma=0.268;
dt=0.05;
T=10;
t=0:dt:T
for tt=1:length(t)
x=gamma*sqrt(((1-cos(0.7255*t(tt))).^2+(sin(0.7255*t(tt))).^2)/((1-gamma*cos(0.7255*t(tt))).^2+(gamma^2)*(sin(0.7255*t(tt))).^2))
y(tt)=abs(x);
end
figure;
plot(t,y); grid on;
title('1b)')
xlabel('frequncy (GHz)')
ylabel('|Gamma|')
More: No Loop is required here, try
gamma=0.268;
dt=0.05;
T=10;
t=0:dt:T;
x=gamma*sqrt((1-cos(0.7255*t).^2+(sin(0.7255*t)).^2)./((1-gamma*cos(0.7255*t)).^2+(gamma^2)*(sin(0.7255*t)).^2));
y=abs(x);
figure;
plot(t,y); grid on;
title('1b)')
xlabel('frequncy (GHz)')
ylabel('|Gamma|')
Related Question