Read Excel and write the output in same sheet in three columns
조회 수: 2 (최근 30일)
이전 댓글 표시
status = mkdir('D:\PK90'); cd D:\PK90
filename = 'sample.xlsx'; % path to your file, e.g., 'D:\PK79\Book1.xlsx'
% read the file to a table:
T = readtable(filename);
Q = 1; Da = 0.5; K = 0.1; G = 0.1; bt = 2; Pr = 2; Nb = 0.1; Nt = 0.1;
Le = 1; K1 = 0.01; a1 = 0.1; a2 = 0.1; % Rd = 0.75; A = 0.15; B = 0.15;
BC = @(ya,yb)[ ya(1); ya(2)-1; ya(5) + a1*(1-ya(4)); ya(7) + a2*(1-ya(6)); yb([2,4,6]); ];
ODE = @(x,y) [ y(2); y(3); (-y(1)*y(3) + y(2)^2 - Q*exp(-bt*x) + Da*y(2))/(1+K-K*G*y(3)^2);
y(5); ((-Pr*(Nb*y(5)*y(7) + y(1)*y(5) + Nt*y(5)^2)) - A*y(2) - B*y(4))/(1+(4*Rd)/3);
y(7); -Le*Pr*(y(1)*y(7) - K1*y(6)) - (Nt/Nb)*((-Pr*(Nb*y(5)*y(7) + y(1)*y(5) + Nt*y(5)^2)) - A*y(2) - B*y(4))/(1+(4*Rd)/3);];
xa = 0;xb = 6; x = linspace(xa,xb,100); solinit = bvpinit(x,[0 1 0 1 0 1 0]); sol = bvp5c(ODE,BC,solinit); S = deval(sol,x);
Cf = ( (1+K)*S(3,1) - ((K*G*S(3,1)^3)/3)); Nu = -(1 + (4*Rd)/3)*S(5,1); Sh = -S(7,1);
disp ([Cf Nu Sh])
writetable(T,filename,'WriteMode','overwritesheet')
% check the result:
T = readtable(filename)
%% I need to write the calculations of Cf, Nu and Sh in the sheet
댓글 수: 0
채택된 답변
Voss
2024년 1월 14일
@MINATI PATRA: Check and see if this seems right:
filename = 'sample.xlsx'; % path to your file, e.g., 'D:\PK79\Book1.xlsx'
% read the file to a table:
T = readtable(filename)
Q = 1; Da = 0.5; K = 0.1; G = 0.1; bt = 2; Pr = 2; Nb = 0.1; Nt = 0.1;
Le = 1; K1 = 0.01; a1 = 0.1; a2 = 0.1; %Rd = 0.75; A = 0.15; B = 0.15;
Rd = T.Rd;
A = T.A;
B = T.B;
xa = 0;
xb = 6;
x = linspace(xa,xb,100);
N = size(T,1);
Cf = zeros(N,1);
Nu = zeros(N,1);
Sh = zeros(N,1);
for k = 1:N
BC = @(ya,yb)[ ya(1); ya(2)-1; ya(5) + a1*(1-ya(4)); ya(7) + a2*(1-ya(6)); yb([2,4,6]); ];
ODE = @(x,y) [ y(2); y(3); (-y(1)*y(3) + y(2)^2 - Q*exp(-bt*x) + Da*y(2))./(1+K-K*G*y(3)^2);
y(5); ((-Pr*(Nb*y(5)*y(7) + y(1)*y(5) + Nt*y(5)^2)) - A(k)*y(2) - B(k)*y(4))./(1+(4*Rd(k))/3);
y(7); -Le*Pr*(y(1)*y(7) - K1*y(6)) - (Nt/Nb)*((-Pr*(Nb*y(5)*y(7) + y(1)*y(5) + Nt*y(5)^2)) - A(k)*y(2) - B(k)*y(4))./(1+(4*Rd(k))/3);];
solinit = bvpinit(x,[0 1 0 1 0 1 0]);
sol = bvp5c(ODE,BC,solinit);
S = deval(sol,x);
Cf(k) = ( (1+K)*S(3,1) - ((K*G*S(3,1)^3)/3));
Nu(k) = -(1 + (4*Rd(k))/3)*S(5,1);
Sh(k) = -S(7,1);
end
disp ([Cf Nu Sh])
T.Cf = Cf;
T.Nu = Nu;
T.Sh = Sh;
vars = T.Properties.VariableNames;
T = removevars(T,vars(startsWith(vars,'Var')));
writetable(T,filename,'WriteMode','overwritesheet')
% check the result:
T = readtable(filename)
추가 답변 (1개)
Ayush Modi
2024년 1월 14일
Hi Minati,
I ran the code and got the following error - Unrecognized function or variable 'A'.
Upon checking the code, I observed that the variable "A" is commented in the code.
Le = 1; K1 = 0.01; a1 = 0.1; a2 = 0.1; % Rd = 0.75; A = 0.15; B = 0.15; -- Original code
After correcting the code with the following changes, the code worked fine.
Le = 1; K1 = 0.01; a1 = 0.1; a2 = 0.1; Rd = 0.75; A = 0.15; B = 0.15;
Hope this helps!
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!