Clear Filters
Clear Filters

How to get out of this error:'You can not subscript a table using only one subscript. Table subscripting requires both row and variable subscripts', while data fitting in NRTL thermodynamic model

3 views (last 30 days)
I am trying to data fit in NRTL thermodynamic model where i have Five input variables which i wrote it in one matrix xd, and one output accroding to that five input that i wrote it in yd column matrix. where 'a' is Constants that i want to get for this Data. alpha is another constant which value remains same and which value input we also gave.
below is my code:
clear all;
clc;
alpha=0.3;
xd(:,1) = readtable('Data2.xlsx','Sheet',1,'Range','A2:A41')
xd(:,2) = readtable('Data2.xlsx','Sheet',1,'Range','B2:B41')
xd(:,3) = readtable('Data2.xlsx','Sheet',1,'Range','C2:C41')
xd(:,4) = readtable('Data2.xlsx','Sheet',1,'Range','D2:D41')
xd(:,5) = readtable('Data2.xlsx','Sheet',1,'Range','E2:E41')
yd = readtable('Data2.xlsx','Sheet',2,'Range','A2:A41')
a0=[-68.7129 -5.3215 0.0615 -13.7754 -7.7847 -73.611 -0.4944 -1.5439 -0.0677 1.5985 1.5728 0.4826];
for K = 1 : height(yd)
options = optimoptions('lsqcurvefit','Algorithm','trust-region-reflective','MaxFunEvals',800000,'MaxIter',300000,'TolX',1e-10,'TolFun',1e-10)
lb = [];
ub = [];
[a{K}, resnorm{K}]= lsqcurvefit( @(a,xd) curvefit_multiobjective_two(a, xd{K}), a0, xd{K} , yd{K}, lb, ub, options);
end
C=[0 a(1) a(2); a(3) 0 a(4); a(5) a(6) 0]
D=[0 a(7) a(8); a(9) 0 a(10); a(11) a(12) 0]
where NRTL data is also attached below:(Pl. note that actual data is not listed for security purposes)
File name for data is : Data2.xlsx
the calling function code is written below:
function yd=curvefit_multiobjective_two(a,xd)
alpha=0.3;
tow11=0;
tow12=(a(1)+(a(7)./(xd(:,1))));
tow13=(a(2)+(a(8)./(xd(:,1))));
tow21=(a(3)+(a(9)./(xd(:,1))));
tow22=0;
tow23=(a(4)+(a(10)./(xd(:,1))));
tow31=(a(5)+(a(11)./(xd(:,1))));
tow32=(a(6)+(a(12)./(xd(:,1))));
tow33=0;
G11=exp(-alpha.*tow11);
G12=exp(-alpha.*tow12);
G13=exp(-alpha.*tow13);
G21=exp(-alpha.*tow21);
G22=exp(-alpha.*tow22);
G23=exp(-alpha.*tow23);
G31=exp(-alpha.*tow31);
G32=exp(-alpha.*tow32);
G33=exp(-alpha.*tow33);
a1=((xd(:,2).*tow11.*G11)+(xd(:,3).*tow21.*G21)+((1-xd(:,2)-xd(:,3)).*tow31.*G31))./((xd(:,2).*G11)+(xd(:,3).*G21)+((1-xd(:,2)-xd(:,3)).*G31));
a2=((xd(:,2).*G11)./((xd(:,2).*G11)+(xd(:,3).*G21)+((1-xd(:,2)-xd(:,3)).*G31))).*(tow11-(((xd(:,2).*tow11.*G11)+(xd(:,3).*tow21.*G21)+((1-xd(:,2)-xd(:,3)).*tow31.*G31))./((xd(:,2).*G11)+(xd(:,3).*G21)+((1-xd(:,2)-xd(:,3)).*G31))));
a3=((xd(:,3).*G12)./((xd(:,2).*G12)+(xd(:,3).*G22)+((1-xd(:,2)-xd(:,3)).*G32))).*(tow12-(((xd(:,2).*tow12.*G12)+(xd(:,3).*tow22.*G22)+((1-xd(:,2)-xd(:,3)).*tow32.*G32))./((xd(:,2).*G12)+(xd(:,3).*G22)+((1-xd(:,2)-xd(:,3)).*G32))));
a4=(((1-xd(:,2)-xd(:,3)).*G13)./((xd(:,2).*G13)+(xd(:,3).*G23)+((1-xd(:,2)-xd(:,3)).*G33))).*(tow13-(((xd(:,2).*tow13.*G13)+(xd(:,3).*tow23.*G23)+((1-xd(:,2)-xd(:,3)).*tow33.*G33))./((xd(:,2).*G13)+(xd(:,3).*G23)+((1-xd(:,2)-xd(:,3)).*G33))));
a5=((xd(:,2).*tow12.*G12)+(xd(:,3).*tow22.*G22)+((1-xd(:,2)-xd(:,3)).*tow32.*G32))./((xd(:,2).*G12)+(xd(:,3).*G22)+((1-xd(:,2)-xd(:,3)).*G32));
a6=((xd(:,2).*G21)./((xd(:,2).*G11)+(xd(:,3).*G21)+((1-xd(:,2)-xd(:,3)).*G31))).*(tow21-(((xd(:,2).*tow11.*G11)+(xd(:,3).*tow21.*G21)+((1-xd(:,2)-xd(:,3)).*tow31.*G31))./((xd(:,2).*G11)+(xd(:,3).*G21)+((1-xd(:,2)-xd(:,3)).*G31))));
a7=((xd(:,3).*G22)./((xd(:,2).*G12)+(xd(:,3).*G22)+((1-xd(:,2)-xd(:,3)).*G32))).*(tow22-(((xd(:,2).*tow12.*G12)+(xd(:,3).*tow22.*G22)+((1-xd(:,2)-xd(:,3)).*tow32.*G32))./((xd(:,2).*G12)+(xd(:,3).*G22)+((1-xd(:,2)-xd(:,3)).*G32))));
a8=(((1-xd(:,2)-xd(:,3)).*G23)./((xd(:,2).*G13)+(xd(:,3).*G23)+((1-xd(:,2)-xd(:,3)).*G33))).*(tow23-(((xd(:,2).*tow13.*G13)+(xd(:,3).*tow23.*G23)+((1-xd(:,2)-xd(:,3)).*tow33.*G33))./((xd(:,2).*G13)+(xd(:,3).*G23)+((1-xd(:,2)-xd(:,3)).*G33))));
gamma_one=exp(a1+a2+a3+a4);
gamma_two=exp(a5+a6+a7+a8);
yd=(xd(:,2).*gamma_one.*xd(:,4))+(xd(:,3).*gamma_two.*xd(:,5));
end
please help me out of this error:'You can not subscript a table using only one subscript. Table subscripting requires both row and variable subscripts.'
Thank you in advance.

Accepted Answer

Walter Roberson
Walter Roberson on 13 Jan 2020
[a{K}, resnorm{K}]= lsqcurvefit( @(a,xd) curvefit_multiobjective_two(a, xd{K}), a0, xd{K} , yd{K}, lb, ub, options);
The xd inside the @ function definition is not the same xd as after the a0 in the call. The one after the a0 is a table object. When you access a table object with {} indexing, you must use two subscripts, such xd{K,:}
  3 Comments
Ashish Kundaliya
Ashish Kundaliya on 14 Jan 2020
Thank you, sir for this helpful answer. Now this error has been resolved but my main Aim is to Data fit into This NRTL thermodynamic model for ternary mixture. While solving this above code i have to give some intial guess(Obvious) for getting that Constant (a Value). but i am getting trouble into giving its initial guess, as what initial guess will give me best fit. because till now i have tried number of intial guess and got the result but it was not upto the mark. so, is there any technique for Data fitting where that method will take initial guess on its own and give me best fit..???
Pl. note that constant a is a set of matrix which consist of 12 constant value in it. where principle diagonal value of matrix is Zero and so this is two sets of 3*3 matrix.

Sign in to comment.

More Answers (0)

Categories

Find more on Thermodynamics and Heat Transfer 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!