MATLAB Help with MATLAB Error: "Subscript Indices Must Be Real Positive Integers

  • Thread starter Thread starter Arkane1337
  • Start date Start date
  • Tags Tags
    Matlab
AI Thread Summary
The discussion focuses on resolving an error encountered in MATLAB related to indexing within a plot function. The user is confused about the second part of their code, specifically how to correctly reference elements in a vector. The error message indicates that MATLAB requires positive integer indices or logicals, but the user is attempting to use non-integer values for indexing. The solution involves defining the variable y directly, rather than using functional notation. The correct approach is to define y as a function of t without using y(t), which leads to valid indexing. An example provided shows how to define y using exponential functions and suggests starting the plot with y defined as y = exp(-t./2).*exp(-2*t).
Arkane1337
Messages
7
Reaction score
0
http://i.snag.gy/FBeLq.jpg

I've figured out the first part, (a), it's the second part (b) that's confusing- I've tried re-arranging the plot() function and also tinkering with y1 and y2 rather than y(t), as I get the error:

"Subscript indices must either be real positive integers or logicals."

Any help or advice?
 
Physics news on Phys.org
Anyone..?
 
y(t) is functional notation in mathematics. In MATLAB, y(t) means the t-th element in y. In this case t is even a vector of (noninteger) values, so you end up telling MATLAB you want to look at y(0.05), which doesn't make sense since y doesn't have a 0.05th element, only a 1st, 2nd, etc... So just define y = instead of y(t) = .

I'll get you started..
y = exp(-t./2).*exp(-2*t);
x = ...
plot(t,x)
 

Similar threads

Replies
4
Views
2K
Replies
6
Views
5K
Replies
3
Views
15K
Replies
2
Views
2K
Replies
1
Views
3K
Back
Top