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

  • Context: MATLAB 
  • Thread starter Thread starter Arkane1337
  • Start date Start date
  • Tags Tags
    Matlab
Click For Summary
SUMMARY

The forum discussion addresses a MATLAB error: "Subscript indices must be real positive integers or logicals." The issue arises when using non-integer values in the indexing of arrays, specifically when attempting to access elements of the array y using a vector t that contains non-integer values. The correct approach is to define y as a function of t without using functional notation, such as y = exp(-t./2).*exp(-2*t), ensuring that t is defined appropriately for valid indexing.

PREREQUISITES
  • Understanding of MATLAB syntax and array indexing
  • Familiarity with mathematical functions and their implementation in MATLAB
  • Knowledge of vector operations in MATLAB
  • Basic experience with plotting functions in MATLAB
NEXT STEPS
  • Learn about MATLAB array indexing and how to avoid common indexing errors
  • Explore MATLAB's plotting functions and their parameters
  • Study the use of vectorized operations in MATLAB for efficient computations
  • Investigate MATLAB's function handles and how to define functions properly
USEFUL FOR

MATLAB users, data analysts, and engineers who are troubleshooting array indexing issues and seeking to improve their understanding of MATLAB's functional programming capabilities.

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 5 ·
Replies
5
Views
3K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 6 ·
Replies
6
Views
6K
  • · Replies 3 ·
Replies
3
Views
15K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K