Indexing error in MATLAB coding project

In summary, the conversation discusses a MATLAB project that evaluates parameters of a spring mass system and displays the results through graphs and animations. The user is allowed to input different coefficients, but the program gives an error in certain cases. The conversation suggests using the error message to check for non-integer inputs and to use a stepping debugger to identify the error in the code.
  • #1
cookiemnstr510510
162
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: 373
  • matlabError.JPG
    matlabError.JPG
    19.5 KB · Views: 389
  • Spring Mass Code project.docx
    19.1 KB · Views: 296
  • Spring Mass Code project.docx
    19.1 KB · Views: 287
  • matlabError.JPG
    matlabError.JPG
    19.5 KB · Views: 333
Physics news on Phys.org
  • #2
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.
 
  • #3
What is 'circular' supposed to do ? Where is it ?
Idem feval and gui_mainfcn ?
 
  • #4
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.
 

1. What is an indexing error in MATLAB coding?

An indexing error in MATLAB coding occurs when the index used to access a specific element in an array or matrix is out of bounds or incorrect. This can result in unexpected or incorrect outputs from the code.

2. How do I know if my MATLAB coding project has an indexing error?

You can identify an indexing error in your MATLAB coding project by looking for any "index out of bounds" or "index exceeds matrix dimensions" error messages in the command window. These errors will also provide information about the line of code where the error occurred.

3. What are some common causes of indexing errors in MATLAB coding?

Some common causes of indexing errors in MATLAB coding include using incorrect or out of bounds indices, mismatched dimensions of arrays or matrices, and forgetting to initialize or preallocate variables before assigning values to them.

4. How can I prevent indexing errors in my MATLAB coding project?

To prevent indexing errors in your MATLAB coding project, it is important to carefully check and double-check the indices used to access elements in arrays or matrices. You should also pay attention to the dimensions of your arrays and preallocate variables before assigning values to them.

5. How can I fix an indexing error in my MATLAB coding project?

The first step in fixing an indexing error in your MATLAB coding project is to identify the line of code where the error occurred. Then, you can check the indices and dimensions used in that line of code and make any necessary corrections. You may also need to review the logic of your code to ensure that the correct indices are being used to access the desired elements.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
574
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
862
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
Back
Top