MATLAB Indexing error in MATLAB coding project

AI Thread Summary
The discussion centers on a MATLAB project focused on evaluating parameters of a spring mass system, allowing user inputs for initial position, velocity, mass, spring constant, damping coefficient, and external force. The program computes a differential equation, graphs results, and includes an animation. The user encounters an error when inputting certain parameters and seeks assistance, providing attachments of the error message and code. Suggestions for troubleshooting include checking if the spring constant is an integer using the isinteger() function, clarifying the purpose of certain functions like 'circular', and utilizing MATLAB's stepping debugger to identify issues in the code. The emphasis is on systematically reviewing the code from the lowest function in the stack trace to ensure correct inputs and function calls.
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: 426
  • matlabError.JPG
    matlabError.JPG
    19.5 KB · Views: 433
  • Spring Mass Code project.docx
    Spring Mass Code project.docx
    19.1 KB · Views: 354
  • Spring Mass Code project.docx
    Spring Mass Code project.docx
    19.1 KB · Views: 349
  • matlabError.JPG
    matlabError.JPG
    19.5 KB · Views: 401
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
Views
4K
Replies
5
Views
2K
Replies
4
Views
1K
Replies
1
Views
3K
Replies
3
Views
3K
Replies
3
Views
2K
Back
Top