Indexing error in MATLAB coding project

Click For Summary

Discussion Overview

The discussion revolves around a MATLAB coding project related to a spring mass system. The participant describes an issue with an indexing error that occurs when certain parameters are inputted into the program, which computes a differential equation and generates graphs and animations based on user-defined coefficients.

Discussion Character

  • Homework-related
  • Technical explanation
  • Debate/contested

Main Points Raised

  • The initial post outlines the parameters of the spring mass system and describes the error encountered when specific inputs are provided.
  • One participant suggests checking if the variable 'k' is an integer using the isinteger() function to address potential input issues.
  • Another participant questions the purpose and location of certain functions ('circular', 'feval', and 'gui_mainfcn'), indicating a need for clarification on their roles in the code.
  • A further reply explains the nature of the error report as a stack trace and recommends using MATLAB's stepping debugger to identify issues in the code by examining variable states before function calls.

Areas of Agreement / Disagreement

Participants offer various suggestions for troubleshooting the error, but there is no consensus on the specific cause of the issue or a definitive solution. Multiple approaches are proposed without agreement on which is most effective.

Contextual Notes

The discussion does not clarify the definitions or expected behaviors of certain functions mentioned, nor does it resolve the specific indexing error described. There may be assumptions about the structure of the code that are not explicitly stated.

Who May Find This Useful

Students working on MATLAB projects, particularly those involving simulations of physical systems, may find this discussion relevant. Additionally, individuals troubleshooting coding errors in MATLAB may benefit from the shared insights.

cookiemnstr510510
Messages
162
Reaction score
14
Hello, I am working on a MATLAB project for my intro to MATLAB course. My project evaluates certain parameters of a spring mass system and graphs the result along with a little mock animation.
inputs the user is allowed to change:
Initial Position at time =0
Initial Velocity at time=0
Mass of block
Spring Constant
Damping coefficient
External force

Once the user inputs these coefficients, my program computes the differential equation, graphs the result, and displays an animation that is directly connected to the results. It does a few other things as well, but I believe my error falls somewhere in the described part of my program.

I notice when i type in certain parameters my program gives me the error attached.
I will add several attachments to this post along with my code and hopefully someone can figure out where the issue arises. I am a bit pressed for time since my project is due on Tuesday.
The MyFigure.jpg attachment shows what the output is when I type in the specific numbers that give me the error which is in the attachment matlabError.jpg. I have attached my code in Spring Mass Code Project.docx.

Any help would greatly appreciated!
Thanks in advanced.
 

Attachments

  • MyFigure.JPG
    MyFigure.JPG
    36.7 KB · Views: 445
  • matlabError.JPG
    matlabError.JPG
    19.5 KB · Views: 447
  • Spring Mass Code project.docx
    Spring Mass Code project.docx
    19.1 KB · Views: 373
  • Spring Mass Code project.docx
    Spring Mass Code project.docx
    19.1 KB · Views: 372
  • matlabError.JPG
    matlabError.JPG
    19.5 KB · Views: 415
Physics news on Phys.org
You could follow the lead from the error message and do a check see if 'k' is, in fact, an integer. Use isinteger() to catch a non-integer case.
 
What is 'circular' supposed to do ? Where is it ?
Idem feval and gui_mainfcn ?
 
The error report you show is a stack trace. The error occurred in the lowest function and percolated back to the top function. I look at th lowest function that is my code and start from there making sure I called whatever function with the correct inputs and array inputs.

I believe Matlab has a stepping debugger that you can use to step through your code and look at variables before they are passed to a function. Often just stepping through your code you will spot the error.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K