Index Out of Bounds Error - Troubleshooting in MATLAB

  • Context: MATLAB 
  • Thread starter Thread starter roldy
  • Start date Start date
  • Tags Tags
    Bounds Index
Click For Summary
SUMMARY

The forum discussion addresses an "Index Out of Bounds" error encountered in MATLAB while calculating the Mach number (M0) for multiple RPM lines. The user initially attempted to access elements of the arrays Tt4_Tt2_ratio, pi_c, eff_c, and mdotcorr2 using a loop indexed by RPMline, which resulted in an error due to the arrays having only one element. The solution involved directly indexing the arrays with the RPMline variable in the formulas, which resolved the issue but raised questions about the underlying cause of the error.

PREREQUISITES
  • Understanding of MATLAB array indexing
  • Familiarity with MATLAB loops and control structures
  • Basic knowledge of thermodynamics concepts such as Mach number
  • Experience with data import from Excel into MATLAB
NEXT STEPS
  • Research MATLAB array manipulation techniques
  • Learn about MATLAB error handling and debugging methods
  • Explore MATLAB's data import functions for Excel files
  • Study the relationship between thermodynamic parameters and their impact on calculations
USEFUL FOR

MATLAB programmers, engineers working with thermodynamic calculations, and anyone troubleshooting array indexing issues in MATLAB.

roldy
Messages
206
Reaction score
2
I'm working on a piece of code to help me generate plots. Right now I'm focusing on the calculation stuff.

Here's what I need to do.
For each RPMline, calculate the Mach number (M0) for mdotf=.1,.2,.3,.4,.5,.6,.7
I read values of Tt4_Tt2_ratio, pi_c, eff_c, mdotcorr2 from the Excel sheet. As you can see in the code, the value of M0 not only depends on mdotf but also Tt4_Tt2_ratio, pi_c, eff_c, mdotcorr2.

So I have an array called mdotf of all the values of mdotf I need to use. This returns an array called M0, which contains all the Mach numbers based on the mdotf used. After doing this for the first RPMline, it should repeat for the second RPMline and keeps doing this until I've done this for all 8 RPMlines. What I tried to do was set up a loop for the RPMline that would increment Tt4_Tt2_ratio, pi_c, eff_c, mdotcorr2.

I'm always getting this message:
Attempted to access Tt4_Tt2_ratio(2); index out of bounds because numel(Tt4_Tt2_ratio)=1.

If, instead of using the loop, I put in values 1-8 in place of the variable RPMline I get a result. There's some kind of indexing problem between MATLAB and Excel but I can't figure out what it is.
 

Attachments

Physics news on Phys.org
Ok, I got this to work by getting rid of

Tt4_Tt2_ratio=Tt4_Tt2_ratio(RPMline);
pi_c=pi_c(RPMline);
eff_c=eff_c(RPMline);
mdotcorr2=mdotcorr2(RPMline);

And in the formulas just added (RPMline) to the end of Tt4_Tt2_ratio,pi_c, eff_c, mdotcorr2. It looks tacky but it works. I would still like to know why MATLAB did not like the way I had it coded.
 

Similar threads

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