Trying to take mean of group of values and exclude one value, receiving error: Index exceeds the number of array elements (0)
Afficher commentaires plus anciens
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)]);
R=287.058;
P=xlsread('Lab2Data.xlsx', 'D1:D1');
Pc=29.77;
Pa=Pc*3386.39;
% Temp
TF=71;
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)]);
Réponses (1)
randerss simil
le 14 Fév 2021
%if true
q01=xlsread('Lab2Data.xlsx', 'B6:B41');
Can you Check if the Lab2Data.xlsx has any empty cells between B6:B41?
6 commentaires
randerss simil
le 14 Fév 2021
Modifié(e) : randerss simil
le 14 Fév 2021
Or some special characters / alphabets
If the imported data has any empty cells, then you're trying to access more cells. It reduces something less than 35
Alicia
le 14 Fév 2021
Walter Roberson
le 14 Fév 2021
After you calculate up through p74, what shows up for size() of the p variables?
randerss simil
le 14 Fév 2021
I tried your rearranged data file,
This shows "B6:B41" gives me 33x1 double array. Though data values are present only till 38th row, when you import using xlsread, it will create workspace variable with 33x1 double array only
This means, if you use
%if true
q01=xlsread('Lab2DataRearranged.xlsx', 'B6:B41');
You will get q01 as 33x1 double array
So, you have to use
%if true
q01=xlsread('Lab2DataRearranged.xlsx', 'B4:B38');
Also, in the previous xls file Lab2Data_.xlsx, the data values are arranged in horizontal manner, i.e. columns A to AI, and not B6:B41
So you have to access using
%if true
q01=xlsread('Lab2Data.xlsx', 'A6:AI6');
Try above, with your earlier file
Alicia
le 14 Fév 2021
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!