MATLAB Index Out of Bounds Error - Troubleshooting in MATLAB

  • Thread starter Thread starter roldy
  • Start date Start date
  • Tags Tags
    Bounds Index
AI Thread Summary
The discussion centers on generating plots through code that calculates the Mach number (M0) for various mass flow rates (mdotf) across multiple RPM lines. The user is attempting to read parameters such as Tt4_Tt2_ratio, pi_c, eff_c, and mdotcorr2 from an Excel sheet and use them in a loop to compute M0 for each RPM line. However, an indexing error occurs, indicating that the code attempts to access an element outside the bounds of the Tt4_Tt2_ratio array. The issue is resolved by directly indexing the parameters with the RPM line variable in the formulas, rather than trying to assign them to new variables. This workaround, while functional, raises questions about the original indexing problem in MATLAB, highlighting potential discrepancies in how MATLAB handles array dimensions compared to Excel data.
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

Back
Top