Help writing a for loop to calculate trapezoid rule at from different rows

1 view (last 30 days)
XS=xlsread('/Users/nicktavares/Documents/MATLAB/SnSe_TE_properties_data.xlsx','D12:D87');
YS=xlsread('/Users/nicktavares/Documents/MATLAB/SnSe_TE_properties_data.xlsx','E2:E87');
S=trapz(XS,YS) ; %Seebeck w/ respect to temp approximate area(tc,tH)
A=S.^2;
XR=xlsread('/Users/nicktavares/Documents/MATLAB/SnSe_TE_properties_data.xlsx','A8:A80');
YR=xlsread('/Users/nicktavares/Documents/MATLAB/SnSe_TE_properties_data.xlsx','B2:B80');
R=trapz(XR,YR);%Kappa
T=(948.8230-301.4110); %Delta T
XK=xlsread('/Users/nicktavares/Documents/MATLAB/SnSe_TE_properties_data.xlsx','G13:G83');
YK=xlsread('/Users/nicktavares/Documents/MATLAB/SnSe_TE_properties_data.xlsx','H2:H83');
K=trapz(XK,YK);% Thermal conductivity with respect to temp approx area(tc,TH)
R1=(1/K); %Rho Thermal Resistivity
Z=(A/(R1*R))*T; %Engineering Dimensionless figure of merit
H=3.4347399999999997*10^(-4);
P=H*T/S;
N=(1-(301.4110/948.8230));
Q=(P/N);
G1=(sqrt(1+(Z*(Q-(1/2))))-1);
G2=(P*(sqrt(1+(Z*(Q-(1/2))))+1)-N);
G3=(N*(G1/G2)); %Maximum Efficiency
% code
Instead of finding the areas for all the values of X and Y, I would need calculate trapezoid rule at 6 different Delta T (Tc,Th) with the Corresponding Y values . And have T = those 6 different Delta T's. (All of the ranges chosen are very precise to one another the 6 delta T's I'm looking for. But I would need:
x='D12:D18' corresponding y='E12:E18' Delta T 1
x='D12:D31' y='E12:E31' Delta T 2
x='D12:D40' '''''''''''''Delta T3
x='D12:D46'...........Delta T 4
x='D12:D54'..........Delta T 5
x='D12:D67'.......Delta T 6
T = 75 for Delta T 1, 150 for Delta T 2, 225 for Delta T 3, 300 for Delta T 4, 375 for Delta T 5, 450 for Delta T 6
(This isn't code just general Idea)
Pretty much I need to do a for loop for those different ranges of x and y that will calculate G3 for i= (1:6) . So I could just type in G3 in command and get the 6 different values for G3 at those different ranges. I hope this makes sense. Any help is appreciated I'm very confused .

Answers (1)

Geoff Hayes
Geoff Hayes on 7 Nov 2015
Nicholas - you have read the D and E column data into XS and YS respectively, and so you are required to process subsets of this data on each iteration of a loop. So you need an array of "end" indices (since the start is always D12 and E12 (or the first element in XS and YS)) which you can create as follows
endIndices = [18 31 40 46 54 67] - 12 + 1;
Then just iterate over the above array and determine your x and y as
for k=1:length(endIndices)
x = XS(1:endIndices(k));
y = YS(1:endIndices(k));
% etc.
end
Would the above be sufficient?

Community Treasure Hunt

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

Start Hunting!