The logical indices in position 1 contain a true value outside of the array bounds.

2 vues (au cours des 30 derniers jours)
Hello,
I'm working on a project to plot the efficency versus temperature input for a supercritical CO2 Brayton cycle. I have hogg-pogged together a code, but seem to be running into an issue.
I have an Excel workbook with 2 sheets with temperature (T), pressure (P), density (rho), enthalpy (h), entropy (s), Cp, and Cv. I want matlab to run through a range of temperature inputs (T1), find that value in the first excel sheet. Once that row is found, I can assign those values to the corresponding variables. Using T1, matlab will calculate T2, look through the second excel sheet, and assign the corresponding values to the correct variables; and so forth and so on.
I'm currently running into an issue with my Cp1 value. I gett the error "The logical indices in position 1 contain a true value outside of the array bounds." I cannot figure out where the issue is. Here is my code:
%Supercritical CO2
function [eff] = sCO2()
%DATA
filename = 'Table sCO2.xlsx';
x=.95;
Cp1=1;
Temp_Range=[];
Eff_Range=[];
Enth_Range=[];
eff_turb = 0.85; % efficency of the turbine
T1 = 100;% degrees C
h1 = 1611.1;
P1 = 25; %MPa
s1 = 3.2538;
T2 = 50;
P2 = 8; %MPa
h2 = 1611.1; %kJ/kg
s2 = 3.4766; %kJ/kgK
T3 = 75;
h3 = 1385.7;
P3 = P2;
s3 = 3.2862;
T4 = 200;
h4 = 752.77;
P4 = P1;
s4 = 2.5073;
P5 = P1;
T5 = 300; % degrees C
h5 = 718.33; % kJ/kg
s5 = 2.2956; %kJ/kgK
tabl1 = xlsread(filename,1);
tabl2 = xlsread(filename,2);
while T1 <=1720.0;
[idx1]=tabl1==T1;
Cp1=tabl1(idx1,7)
T2 = (P2*T1)/P1;
[idx2]=find(tabl2==T2);
T4= 27*(1+(x-1)/.85);
T3 = T2+0.85*(T4-T2);
h3 = tabl2(idx2,4);
T5 = T4 +0.85*(T2-T3);
h4 = tabl2(idx2,4);
h5 = tabl1(idx2,4);
Wcomp = (h3-h4);
Wturb = (h1-h2);
Q_in = Cp1*(T1-T2);
eff=(Wturb-Wcomp)/(Q_in);
Eff_Range=[Eff_Range,eff]; %Creating a vector of efficiencies
Temp_Range=[Temp_Range,T1]; %Vector of Temperatures
T1=T1+10;
end
k=(Eff_Range>0); %eliminating any efficiencies lower than 0 from the plot
figure(1)
plot(Eff_Range(k),Temp_Range(k))
title('Temperature Vs. Efficiency')
ylabel('Temperature Range')
xlabel('Efficiency Range')
when I run it I get:
The logical indices in position 1 contain a true value outside of the array bounds.
Error in sCO2 (line 48)
Cp1=tabl1(idx1,7)
Please, I've looked up a lot of help sites and have explored the questions on here, but cannot figure out how to get this code to work. I've attached the excel files incase they are needed for help. Thank you in advance.

Réponses (1)

Image Analyst
Image Analyst le 21 Nov 2018
You say
[idx1]=tabl1==T1;
Cp1=tabl1(idx1,7)
but tabl1 is 1970 by 7, so that means idx1 is a 1970x7 matrix, not a single number or a vector, so it can't be used as the first index of tabl1. Not sure what you want to do because the code is not commented nearly well enough. But you need to figure out why you're passing a 2-D matrix into the first index position of tabl1.

Catégories

En savoir plus sur Data Import from MATLAB dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by