MATLAB: I want to determine the value of is(.2) but keep getting an error.

function

t=-.2:.0001:0;
is=2;
plot(t,is)
hold on
t=0:.01:2;
is=4-2*exp(-2*t);
plot(t,is)
xlabel('Time(s)')
ylabel('Current is(t)A')
ylim([1 4.5])

Best Answer

interp1(t, is, 0.2)
Or closer to what you are probably thinking of:
[~, idx] = min(abs(t - 0.2));
is(idx)
You cannot index at a floating point number for one thing. But also, your t vector is unlikely to have an entry that is bitwise identical to 0.2 because of floating point roundoff problems reflecting the fact that 0.01 is not exactly representable in binary floating point, for the same reason that 1/7 is not exactly representable in finite decimal.