MATLAB plotting/indexing problem

  • MATLAB
  • Thread starter lmc2191
  • Start date
  • Tags
    Matlab
In summary, the conversation is about an individual having trouble with a MATLAB program. They encounter an error message and after making a small change, they are able to fix it. The conversation also briefly discusses the use of "./" and how it differs from integer division.
  • #1
lmc2191
2
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
  • #2
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
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)"
 

1. What is a MATLAB plotting/indexing problem?

A MATLAB plotting/indexing problem refers to difficulties or errors encountered when trying to create or manipulate plots and/or indices in MATLAB. This can include issues with plotting specific data points, labeling axes, or accessing and manipulating data within arrays using indexing methods.

2. How can I plot specific data points in MATLAB?

To plot specific data points in MATLAB, you can use the "plot" function and specify the x and y values of the points you want to plot. For example, if you have an array of x values stored in the variable "x" and an array of corresponding y values stored in the variable "y", you can use the command "plot(x, y)" to plot those points on a graph.

3. How do I label axes in a MATLAB plot?

To label axes in a MATLAB plot, you can use the "xlabel" and "ylabel" functions. For example, if you want to label the x-axis as "Time (s)" and the y-axis as "Temperature (°C)", you can use the commands "xlabel('Time (s)')" and "ylabel('Temperature (°C)')".

4. What is indexing in MATLAB?

Indexing in MATLAB is a way to access and manipulate specific elements within an array. It allows you to specify which elements of an array you want to work with, rather than having to work with the entire array at once. Indexing can be done using numerical indices, logical indices, or character indices.

5. How can I access and manipulate data within arrays in MATLAB?

To access and manipulate data within arrays in MATLAB, you can use indexing methods. For example, to access a specific element within an array, you can use its numerical index (e.g. array(3) to access the third element). To manipulate multiple elements at once, you can use logical indexing (e.g. array(array > 10) to access all elements that are greater than 10). You can also use character indices to access elements based on their names or labels.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
7K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
9K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
26K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
30K
Replies
2
Views
2K
Back
Top