I am trying to adapt a script that I wrote in MATLAB to be able to run in Octave, the error occurs at the first iteration of this for loop:
for b = (tp/ts):(td/ts)
Vc(b) = Vc(a) + (Vs-Vc(a)).*M(b-(tp/ts-1));
I(b) = (Vs-Vc(b))./R;
end
>> tp/ts
ans = 1.0000e+04
>> Vc(tp/ts) = 5;
error: Vc(10000-1.81899e-12): subscripts must be either integers 1 to (2^63)-1 or logicals
>> Vc(1e4) = 5;
>>
As you can see from the console, when I try to index Vc using tp/ts it throws the error, but when I use the value of tp/ts as the index it works fine. Can anybody explain where the extra "-1.81899e-12" is coming from in the index? And is there a workaround for this issue?
Thanks.
Edit: Changed screenshot images to text. This is my first question on here so thanks for your patience.