MATLAB MATLAB plotting/indexing problem

  • Thread starter Thread starter lmc2191
  • Start date Start date
  • Tags Tags
    Matlab
AI Thread Summary
The MATLAB user encountered an error while attempting to index the array IDS1, which indicated that the index must be a positive integer or logical. The issue arose from using the division operator "./", which performs element-wise division rather than returning an integer. The user resolved the problem by converting the index to an integer using the int16 function. Other suggested alternatives included using the fix or round functions for similar results. The discussion clarified the distinction between element-wise and matrix operations in MATLAB.
lmc2191
Messages
2
Reaction score
0
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)
endFindYs0 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.
 
Physics news on Phys.org
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?
 
lmc2191 said:
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?

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)"
 
Back
Top