0
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.

4
  • 1
    see here for answer. Commented Mar 7, 2013 at 6:38
  • lol @Parag that's his repost xD Commented Mar 7, 2013 at 6:39
  • @Cashew ya I knew as soon as saw the question Commented Mar 7, 2013 at 7:54
  • Also see this question for the generic solution to this problem. Commented Nov 27, 2013 at 16:09

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.