Reputation: 15
for t=0:0.1:10;
VS=3*exp(-t/3).*sin(t*pi);
if VS>0
VL(t+1)=VS;
else
VL(t+1)=0;
end
end
plot(0:100,VL);
xlabel('Time(s)')
ylabel('Across Voltage(V)')
title('Across Voltage Vs Time')
how to plot this figure based on VL (based on the relationship with VS whose expression shows above) versus t(from 0 to 10, increment 0.01)?
always got the error from matlab "Subscript indices must either be real positive integers or logicals."
Thanks.
Upvotes: 0
Views: 134
Reputation: 3249
There is a problem in your script. Note that t is defined in 0.1 intervals. Therefore, it is a real variable and can't be used as a subscript indice.
One way to solve that is
1) write cont=0; before the loop for.
2) write cont=cont+1 in the beginning of the loop
3) replace VL(t+1) by VL(cont)in both places inside the loop
Upvotes: 1