Importing excel column data with row reference?

2 views (last 30 days)
Pressure Data Can someone help me in importing excel data?. I need to import the 'pressure data' in column E with a particular 'angle' as reference in column A. So, if I input 10 deg, the code should take the respective pressure Pcyl data.
%method 1 - delta P%
bore= (79.5/1000); %cylinder diameter in m%
stroke=(80.5/1000); %in m%
a=(stroke/2); %in m%
b=(128/1000); %in m%
gamma= 1.4; %ratio of specific heats
lambda= 1;
R = 287; %J/KgK, gas constant%
LHV= 44*(10^6); %Heat capacity in joules%
N= 1500; %rpm%
AFst= 14.7; %stoichiometric air/fuel ratio for SI engines%
CAD1= input('Enter the CAD at IVC: '); %in CAD, degrees%
CAD2= input('Enter the CAD just before Spark Ignition: '); %in CAD, degrees%
r=10; %compression ratio%
V1=((pi*(bore^2)*stroke)/8) * ((2/(r-1)) + 1 - cos (CAD1) + b - sqrt((b^2) - ((sin (CAD1))^2))); %in cubic meters%
V2=((pi*(bore^2)*stroke)/8) * ((2/(r-1)) + 1 - cos (CAD2) + b - sqrt((b^2) - ((sin (CAD2))^2))); %in cubic meters%
%Input excel data
filename= 'sample_pressure_data_matlab.xlsx';
%Now to find P1
Pcyl1= xlsread(filename);
%Assigning the values of 'a' and 'b' to the size of array 'Pcyl1'
[a,b]=size(Pcyl1);
%Using for loop to sort the row containing CAD1
for i=2:a
if Pcyl1(i,5)==CAD1
P1= Pcyl1(i,5); %bar
disp('P1=');disp(P1);
break
end
end
%Now to find P2
Pcyl2= xlsread(filename);
%Assigning the values of 'c' and 'd' to the size of array 'Pcyl2'
[c,d]=size(Pcyl2)
%Using for loop to sort the row containing the CAD2
for m=2:c
if Pcyl2(m,5)==CAD2
P2= Pcyl2(m,5); %bar
disp('P2=');disp(P2);
break
end
end
T1= 300; %in K, T atCAD1
%calc the total cylinder trapped mass
Mtot=(V1*(V2^gamma)*(P2-P1)*(10^5)) / (R*T1*((V1^gamma)-(V2^gamma))); %kg/cycle
Mfuelhr=1.5; %kg/hr%
Mfuelcyc= (Mfuelhr*2)/(60 * N); %kg/cycle
%Calc the mass of residaul gas
Mrg= (Mtot - (Mfuelcyc*((lambda*AFst)+1))); %kg/cycle
%Calc the mass fraction of residaul gas
Xrg= Mrg/Mtot;
disp('Xrg=');disp(Xrg);

Accepted Answer

Image Analyst
Image Analyst on 25 May 2017
Try this:
allData = xlsread(filename); % Get all the numbers.
% Extract the 3 vectors for the 3 different things:
angles = allData(:, 1);
volumes = allData(:, 2);
pressures = allData(:, 3);
theAngle = 10; % Whatever angle you want
% Find out what index it occurs at.
angleIndex = find(angles == theAngle, 1, 'first')
% Extract pressure and volume for that index
p = pressures(angleIndex)
v = volumes(angleIndex)
  2 Comments
Image Analyst
Image Analyst on 25 May 2017
Well now the announcement is more complicated than you first posted. Actually I call it an announcement because you have not asked an actual question.
If you look at my answer, you should be able to see how to find out the index of an array having a particular value, and then how to get the value of another array having that same index. It's simple, right? Did you even try to apply what I showed you?
Sandeep297
Sandeep297 on 25 May 2017
Edited: Sandeep297 on 25 May 2017
@Image Analyst.. Thanks a lot. I tried to apply ur method for the actual bigger script and its working great...

Sign in to comment.

More Answers (0)

Categories

Find more on Oil, Gas & Petrochemical in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!