Problem with For Loop - Any Help Appreciated

  • Thread starter Thread starter williamrand1
  • Start date Start date
  • Tags Tags
    Loop
Click For Summary

Discussion Overview

The discussion revolves around a problem encountered with a for loop in MATLAB, specifically regarding the use of negative indices and the resulting error. Participants seek assistance in troubleshooting the code provided.

Discussion Character

  • Technical explanation

Main Points Raised

  • One participant presents a code snippet and describes an error related to negative indexing in a for loop.
  • Another participant asks for clarification on the programming language being used.
  • A subsequent reply confirms that the language is MATLAB.
  • A later post indicates that the original poster has resolved the issue independently.

Areas of Agreement / Disagreement

The discussion does not reach a consensus, as the original problem is stated but not elaborated upon after the issue is resolved by the original poster.

williamrand1
Messages
21
Reaction score
0
Hi all,

Im having a problem with the for loop. Any help would be great!

The code is simple,

x = -3:0.5:3;

For i = x

q(i) = i^2;

end

q

The error seems to be the negative index in the statement of the for loop.

Hope this is clear. Thanks!
 
Physics news on Phys.org
What language is this?
 
jtbell said:
What language is this?

Soory for the delay. The language is matlab.
 
Ive figured it out lads so thanks anyway...
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
Replies
3
Views
2K
  • · Replies 12 ·
Replies
12
Views
5K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 29 ·
Replies
29
Views
5K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K