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

  • MATLAB
  • Thread starter Arkane1337
  • Start date
  • Tags
    Matlab
In summary, the conversation discusses how to fix an error involving a plot() function in MATLAB. The error is caused by using functional notation for the variable y(t), which does not have a t-th element. The solution is to define y as a function of t and then plot the function.
  • #1
Arkane1337
7
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
  • #2
Anyone..?
 
  • #3
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)
 

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

What does the error "Subscript Indices Must Be Real Positive Integers" mean?

This error means that you are trying to use a non-integer or negative number as an index in your MATLAB code. This is not allowed because array indices must be whole, positive numbers.

Why am I getting this error?

You are getting this error because there is a mistake in your code that is causing you to use non-integer or negative numbers as indices. This could be due to a typo, a miscalculation, or a misunderstanding of how array indices work in MATLAB.

How can I fix this error?

To fix this error, you will need to carefully check your code and make sure that all of your array indices are real positive integers. This may involve correcting any typos, double-checking your calculations, or reviewing the MATLAB documentation for proper use of indices.

Can I use negative numbers as array indices in MATLAB?

No, you cannot use negative numbers as array indices in MATLAB. Indices must be real positive integers, starting from 1. This is a basic rule in MATLAB and violating it will result in the "Subscript Indices Must Be Real Positive Integers" error.

Is there a way to avoid this error in my code?

Yes, there are a few ways to avoid this error in your code. One way is to carefully check your code for any potential mistakes or miscalculations that could result in non-integer or negative indices. Another way is to use built-in functions or methods in MATLAB that automatically handle indices for you, such as the "find" function or logical indexing.

Similar threads

Replies
4
Views
2K
Replies
1
Views
1K
Replies
6
Views
3K
Replies
4
Views
15K
Replies
13
Views
2K
Replies
2
Views
2K
Replies
1
Views
2K
Replies
4
Views
7K
Back
Top