Discussion Overview
The discussion centers around troubleshooting a for loop in MATLAB, specifically regarding the iteration of a variable and the handling of function outputs. Participants explore issues related to indexing, function definitions, and variable scope within the context of MATLAB programming.
Discussion Character
- Technical explanation
- Debate/contested
- Homework-related
Main Points Raised
- One participant expresses difficulty in getting a for loop to work correctly, specifically wanting to update a variable in each iteration.
- Another participant suggests that the original poster needs to learn how to write functions properly, indicating that calculations are being done only once instead of being updated in each iteration.
- A participant reports encountering an error message related to indexing, specifically mentioning that MATLAB indices start at 1.
- Further clarification is requested regarding the error, with a suggestion that the issue may stem from trying to use a variable as an index.
- A participant provides a code snippet where an error occurs, indicating that the function is attempting to access an index that is not valid.
- Another participant points out that the use of parentheses in the code may be misinterpreted as an array lookup rather than multiplication.
- The original poster mentions that despite implementing a function, the variable is still not being updated correctly across iterations.
- A participant explains that the variable 'a' only exists within the function's scope and does not retain its value after the function execution ends.
- The original poster later expresses gratitude for the assistance received in resolving the issues.
Areas of Agreement / Disagreement
Participants generally agree on the need for proper function usage and the importance of understanding variable scope in MATLAB. However, there are varying levels of understanding regarding the specific error messages and their implications.
Contextual Notes
The discussion highlights limitations in understanding MATLAB's indexing rules and function behavior, particularly concerning variable scope and the need for correct syntax in function definitions.