Trying to take mean of group of values and exclude one value, receiving error: Index exceeds the number of array elements (0)

3 views (last 30 days)
I am trying to take the mean of each group of values, but also excluding the 7th value. I am receiving this error and do not understand how to fix it, even after researching the problem and looking at other people's questions, codes, and suggestions. Here is part of my code below, with the error occurring beginning in the line: m01=mean([p01(1:6), p01(8:35)]);
P=xlsread('Lab2Data.xlsx', 'D1:D1');
% Temp
TK=273.15+((71-32)*(5/9)); % Temp in K 298.15 K
rhoa=Pa/(R*TK); % density P=rhoRT; rho=P/RT
% Data from runs in psi
q01=xlsread('Lab2Data.xlsx', 'B6:B41'); % q=0, run 1
q02=xlsread('Lab2Data.xlsx', 'C6:C41'); % q=0, run 2
q03=xlsread('Lab2Data.xlsx', 'D6:D41'); % q=0, run 3
q04=xlsread('Lab2Data.xlsx', 'E6:E41'); % q=0, run 4
q21=xlsread('Lab2Data.xlsx', 'F6:F41'); % q=2, run 1
q22=xlsread('Lab2Data.xlsx', 'G6:G41'); % q=2, run 2
q23=xlsread('Lab2Data.xlsx', 'H6:H41'); % q=2, run 3
q24=xlsread('Lab2Data.xlsx', 'I6:I41'); % q=2, run 4
q71=xlsread('Lab2Data.xlsx', 'J6:J41'); % q=7, run 1
q72=xlsread('Lab2Data.xlsx', 'K6:K41'); % q=7, run 2
q73=xlsread('Lab2Data.xlsx', 'L6:L41'); % q=7, run 3
q74=xlsread('Lab2Data.xlsx', 'M6:M41'); % q=7, run 4
% Data converted from psi to Pa; 1 psi=6894.76 Pa
p01 = convpres(q01, 'psi', 'Pa');
p02 = convpres(q02, 'psi', 'Pa');
p03 = convpres(q03, 'psi', 'Pa');
p04 = convpres(q04, 'psi', 'Pa');
p21 = convpres(q21, 'psi', 'Pa');
p22 = convpres(q22, 'psi', 'Pa');
p23 = convpres(q23, 'psi', 'Pa');
p24 = convpres(q24, 'psi', 'Pa');
p71 = convpres(q71, 'psi', 'Pa');
p72 = convpres(q72, 'psi', 'Pa');
p73 = convpres(q73, 'psi', 'Pa');
p74 = convpres(q74, 'psi', 'Pa');
% Mean for pressures (in Pa)
m01=mean([p01(1:6), p01(8:35)]);
m02=mean([p02(1:6), p02(8:35)]);
m03=mean([p03(1:6), p03(8:35)]);
m04=mean([p04(1:6), p04(8:35)]);
m21=mean([p21(1:6), p21(8:35)]);
m22=mean([p22(1:6), p22(8:35)]);
m23=mean([p23(1:6), p23(8:35)]);
m24=mean([p24(1:6), p24(8:35)]);
m71=mean([p71(1:6), p71(8:35)]);
m72=mean([p72(1:6), p72(8:35)]);
m73=mean([p73(1:6), p73(8:35)]);
m74=mean([p74(1:6), p74(8:35)]);

Answers (1)

randerss simil
randerss simil on 14 Feb 2021
%if true
q01=xlsread('Lab2Data.xlsx', 'B6:B41');
Can you Check if the Lab2Data.xlsx has any empty cells between B6:B41?
Alicia on 14 Feb 2021
My issue was that I had multiple tabs of data in the excel file I was using, and so I had to name the title of the tab I was taking the data from, next to the title of the excel file I was using in matlab. Thanks for the help nonetheless!

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!