MATLAB indexing error reading Excel values in loop over RPM lines

  • Context: MATLAB 
  • Thread starter Thread starter roldy
  • Start date Start date
  • Tags Tags
    Bounds Index
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 2K views
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.