# MATLAB plotting/indexing problem

1. Sep 29, 2011

### lmc2191

Hello,

I am having a problem getting this MATLAB program to work:

function [ ] = PlotISD()
W = 10^-4;
L = 10^-5;
mu = 400;
Cox = 1.73*10^-6;
VFB = -0.75;
gamma = 0.235;
phiT = 0.0259;
IDS1 = 0:0.05:1.5;
IDS2 = IDS1;
for VGBi = 0:0.05:1.5
Ys0 = FindYs0(VGBi);
YsL = FindYsL(VGBi);
Ysm = (Ys0 + YsL)/2;
am = 1 + gamma/(2*sqrt(Ysm));
index = (VGBi+0.05)./0.05;
IDS1(index) = (W/L)*mu*Cox*(VGBi-VFB-Ysm-gamma*sqrt(Ysm))*(YsL-Ys0);
IDS2(index) = (W/L)*mu*Cox*am*phiT*(YsL-Ys0);
end
VGB0 = 0:0.05:1.5;
IDST = IDS1(1:31) + IDS2(1:31);
plot(VGB0,IDS1,VGB0,IDS2,VGB0,IDST)
end

FindYs0 and FindYsL are functions that do not change the value of VGBi. I keep getting the error message:

??? Attempted to access IDS1(3); index must be a positive integer or logical.

Error in ==> PlotISD at 19
IDS1(index) = (W/L)*mu*Cox*(VGB-VFB-Ysm-gamma*sqrt(Ysm))*(YsL-Ys0);

Last time I checked 3 is a positive integer. What is going on here? Any help would be appreciated.

2. Sep 29, 2011

### lmc2191

Nevermind, I got it.

changed

index = (VGBi+0.05)./0.05;

to

index = int16((VGBi+0.05)./0.05);

I find it strange that I had to do that. Isn't "./" integer division? Shouldn't that output an integer?

3. Sep 29, 2011

### uart

No, "./" means term by term division as opposed to matrix (inverse multiplication) division. Same for ".*" versus "*" and ".^" versus "^".

BTW. You could also have used either "fix((VGBi+0.05)./0.05)" or "round((VGBi+0.05)./0.05)"