Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.

5 visualizaciones (últimos 30 días)
Code Below are two separate functions both returning the following error:
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
Function One:
clear all;
close all;
clc;
T_table = xlsread('air_data_v2','A2','A5:A125');
u_table = xlsread('air_data_v2','A2','B5:B125');
s_table = xlsread('air_data_v2','A2','D5:D125');
h_table = xlsread('air_data_v2','A2','C5:C125');
PR = [1 2 3];
Tmax = [1000 1200 1400];
for i = 1:length(PR)
[KenergyC(i),Nc(i)] = Project2AFunctions1(PR,Tmax);
end
function [KenergyC,Nc] = Project2AFunctions1(PR,Tmax)
R = .287;
Cp = 1.004;
Cv = .7241;
k = Cp/Cv;
%initial state
P1 = 23800; %Pa
T1 = 220; %-54C at 35000 feet in the sky
v1 = R*T1/P1;
%Tmax = 1000;
P2 = P1*3; %Pressure Ratio
Pcompressor = P1:1e3:P2;
for i = 1:length(Pcompressor)
scompressor(i) = xlsread('air_data_v2','A2','D7');
Tcompressor(i) = sqrt(Pcompressor(i));
vcompressor(i) = R*Tcompressor(i)/Pcompressor(i);
end
hcompressor = Cp*(Tcompressor(end)-T1);
%Combustor (State 2)
Tcombustor = 266.08:Tmax(end);
for j = 1:length(Tcombustor)
Pcombustor(j) = Pcompressor(end);
vcombustor(j) = R.*Tcombustor(j)/Pcombustor(j);
scombustor(j) = scompressor(end) + Cp.*log(Tcombustor(j)/Tcombustor(1));
end
hcombustor = Cp*(Tmax(end)-Tcompressor(end));
%Turbine (State 3)
Pturbine = P2:-1e3:P1;
for l = 1:length(Pturbine)
Tturbine(l) = Tcombustor(end).*10.^((R/Cp)*log(Pturbine(l)/P2));
vturbine(l) = ((70800.*vcombustor(end).^k)/(Pturbine(l))).^(1/k);
sturbine(l) = scombustor(end);
end
hturbine = Cp*(999.08-Tcombustor(end));
%Outlet of system (State 4)
Texit = Tcompressor(1):Tturbine(end)+91.779;
for m = 1:length(Texit)
sexit(m) = scompressor(end) + Cp.*log(Texit(m)/Texit(1));
end
Pexit = [Pturbine(end) Pturbine(end)];
vexit = [vcompressor(1) vturbine(end)];
hexit = Cp*(Texit(end)-Tturbine(end));
S3 = sturbine(end);
%5
P5 = P1;
S5 = S3;
V5 = ((Pturbine.*vturbine.^k)/P5).^(1/k);
T5 = (P5.*V5)/R;
h5c = Cp*(T5-Tturbine(end));
%constant CP
KenergyC = h5c-hexit;
Nc = 1-PR.^(-R/Cp);
end
Function two:
clear all;
close all;
clc;
PR = [1 2 3];
Tmax = [1000 1200 1400];
for i = 1:length(PR)
[KenergyNC(i),Nnc(i)] = Project2AFunctions2(PR,Tmax);
end
function [KenergyNC,Nnc] = Project2AFunctions2(PR,Tmax)
R = .287;
Cp = 1.004;
Cv = .7241;
k = Cp/Cv;
T_table = xlsread('air_data_v2','A2','A5:A125');
u_table = xlsread('air_data_v2','A2','B5:B125');
s_table = xlsread('air_data_v2','A2','D5:D125');
h_table = xlsread('air_data_v2','A2','C5:C125');
%non constant
%State 1
p1 = 23800;
t1 = 220;
v1 = R*t1/p1;
s1 = interp1(T_table,s_table,t1);
h1 = interp1(T_table,h_table,t1);
sT1 = interp1(h_table,s_table,h1);
%State 2
s2 = s1;
p2 = p1*PR;
sT2 = sT1 + R*log(p2/p1);
t2 = interp1(s_table,T_table,sT2);
v2 = R*t2/71400;
h2 = interp1(T_table,h_table,t2);
%State 3
p3 = p2;
sT3 = interp1(T_table,s_table,Tmax);
s3 = sT3-sT2 - (R*log(p3/p2))+s2;
v3 = R*Tmax/p3;
h3 = interp1(T_table,h_table,Tmax);
%State 4
h4 = h3+h1-h2;
s4 = s3;
sT4 = interp1(h_table,s_table,h4);
t4 = interp1(h_table,T_table,h4);
p4 = (exp(sT4-sT3)/R).*p3;
v4 = R*t4/p4;
%State 5
s5 = s4;
p5 = p1;
sT5 = sT3+(R*log(p5/p3(1)));
t5 = interp1(s_table,T_table,sT5);
h5 = interp1(T_table,h_table,t5);
v5 = R*t5/p5;
%NonConstant CP
KenergyNC = h5-h4;
Nnc = (h5-h4)/(h3-h2);
end
I would really appreciate knowing what is causing it. Thanks
  2 comentarios
per isakson
per isakson el 23 de Nov. de 2021
We cannot run your code, since we don't have the Excel files. You may not expect us to spot the cause of the error by inspection of the code. You should at least provide the full error message.
Peter Perkins
Peter Perkins el 23 de Nov. de 2021
I really, strongly recommend that you use readtable, or readmatrix, instead of xlsread.
Beyond that set a breakpoint at the line the error is coming from, and figure out what's the wrong size, and work your way backwards to figure out why.

Iniciar sesión para comentar.

Respuestas (1)

KSSV
KSSV el 23 de Nov. de 2021
The error is clear, you are trying to save more number of elements on the LHS then it is intialized for.
Example:
A = zeros(3,3) ; % A should have 3x3 numbers
A(1,:) = rand(1,3) ; % no error, you are saving three elements as it is innitliazed
A(2,:) = rand(1,4) % error, becuase you are trying to save four number instead of 3
Unable to perform assignment because the size of the left side is 1-by-3 and the size of the right side is 1-by-4.

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by