Looping through a column of data from start to end

1 view (last 30 days)
I need to loop through a column data set from start to end so I can calculate an equation.
The equation is given below. Gamma is a known value. CA, P_Pa, V_m3 are all given data that is sorted in a column. The issue that I am having is that when Q_dot_net is solved for, it only gives one value across the whole table. Q_dot_net should be changing based on the data. I am pretty sure this value is calculated from the last two data points in the set.
% read in the cylinder pressure from the excel file
[data] = xlsread('PressureME469.xlsx','PME469');
% split the data into CA and Pressure vectors
CA = data(:,1); % crank angle (deg. ATDC)
P = data(:,2); % cylinder pressure (bar)
P_Pa = P*1e5 % cylinder pressure converstion from bar to Pascal (Pa)
nCA = length(CA); % number of pressure points recorded
for i = 1:length(P_Pa);
for n = 1:length(CA);
for m = 1:length(V_m3);
Q_dot_net(n) = gamma/(gamma-1).*i.*(m-(m-1))/(n-(n-1)) + 1/(gamma-1) + m.*(i-(i-1))/(n-(n-1));
end
end
end
Q_dot_net = Q_dot_net.';
  3 Comments
Drew ARNDT
Drew ARNDT on 30 Nov 2021
I ended getting this to work. There were two extra loops here that were unneccessary
% read in the cylinder pressure from the excel file
[data] = xlsread('PressureME469.xlsx','PME469');
% split the data into CA and Pressure vectors
CA = data(:,1); % crank angle (deg. ATDC)
P = data(:,2); % cylinder pressure (bar)
P_Pa = P*1e5 % cylinder pressure converstion from bar to Pascal (Pa)
nCA = length(CA); % number of pressure points recorded
for i = 2:2880
Q_dot_net(i) = gamma/(gamma-1)*P_Pa(i)*(V_m3(i)-V_m3(i-1))/(CA(i)-CA(i-1)) + 1/(gamma-1) *V_m3(i)*(P_Pa(i)-P_Pa(i-1))/(CA(i)-CA(i-1));
end
Q_dot_net = Q_dot_net.';
This ended up solving the equation for what I needed
Mathieu NOE
Mathieu NOE on 30 Nov 2021
yes , that was more or less what I would have expected !

Sign in to comment.

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!