Read Excel and write the output in same sheet in three columns

조회 수: 2 (최근 30일)
MINATI PATRA
MINATI PATRA 2024년 1월 14일
댓글: MINATI PATRA 2024년 1월 15일
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

채택된 답변

Voss
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)
T = 20×7 table
Rd A B Var4 Var5 Var6 Nu ____ ____ ____ ____ ____ ____ ______ 0.5 0.1 0.1 NaN NaN NaN 0.1321 1 0.1 0.1 NaN NaN NaN 0.179 0.5 0.2 0.1 NaN NaN NaN 0.1213 1 0.2 0.1 NaN NaN NaN 0.1654 0.5 0.1 0.2 NaN NaN NaN 0.1285 1 0.1 0.2 NaN NaN NaN 0.1729 0.5 0.2 0.2 NaN NaN NaN 0.1162 1 0.2 0.2 NaN NaN NaN 0.1573 0.5 0.15 0.15 NaN NaN NaN 0.1247 1 0.15 0.15 NaN NaN NaN 0.169 0.75 0.1 0.15 NaN NaN NaN 0.1536 0.75 0.2 0.15 NaN NaN NaN 0.1406 0.75 0.15 0.1 NaN NaN NaN 0.1497 0.75 0.15 0.2 NaN NaN NaN 0.144 0.75 0.15 0.15 NaN NaN NaN 0.1471 0.75 0.15 0.15 NaN NaN NaN 0.1471
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])
-0.9792 0.1321 0.0870 -0.9792 0.1790 0.0872 -0.9792 0.1213 0.0884 -0.9792 0.1654 0.0884 -0.9792 0.1285 0.0874 -0.9792 0.1729 0.0877 -0.9792 0.1162 0.0889 -0.9792 0.1573 0.0890 -0.9792 0.1247 0.0879 -0.9792 0.1690 0.0880 -0.9792 0.1536 0.0873 -0.9792 0.1406 0.0886 -0.9792 0.1497 0.0877 -0.9792 0.1440 0.0882 -0.9792 0.1471 0.0880 -0.9792 0.1471 0.0880 -0.9792 0.1471 0.0880 -0.9792 0.1471 0.0880 -0.9792 0.1471 0.0880 -0.9792 0.1471 0.0880
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)
T = 20×6 table
Rd A B Nu Cf Sh ____ ____ ____ _______ ________ ________ 0.5 0.1 0.1 0.13206 -0.97916 0.086996 1 0.1 0.1 0.17905 -0.97916 0.087231 0.5 0.2 0.1 0.12132 -0.97916 0.088354 1 0.2 0.1 0.16543 -0.97916 0.088372 0.5 0.1 0.2 0.12845 -0.97916 0.087412 1 0.1 0.2 0.17295 -0.97916 0.087693 0.5 0.2 0.2 0.1162 -0.97916 0.088937 1 0.2 0.2 0.1573 -0.97916 0.088983 0.5 0.15 0.15 0.12467 -0.97916 0.087907 1 0.15 0.15 0.16897 -0.97916 0.088049 0.75 0.1 0.15 0.15364 -0.97916 0.087309 0.75 0.2 0.15 0.14057 -0.97916 0.088615 0.75 0.15 0.1 0.14975 -0.97916 0.087723 0.75 0.15 0.2 0.14403 -0.97915 0.088241 0.75 0.15 0.15 0.14711 -0.97916 0.087962 0.75 0.15 0.15 0.14711 -0.97916 0.087962
  댓글 수: 1
MINATI PATRA
MINATI PATRA 2024년 1월 15일
편집: MINATI PATRA 2024년 1월 15일
@ Voss
your approach is Awesome
I am astonished, how you are getting this level of ideas?
%% Sorry but another problem with an extendd form of this idea is unsolved in the following link
https://in.mathworks.com/matlabcentral/answers/2069876-read-excel-and-write-the-output-in-same-sheet-in-three-columns-extended-form

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Ayush Modi
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!
  댓글 수: 1
MINATI PATRA
MINATI PATRA 2024년 1월 15일
@ Dear Ayush
It has been efficiently solved following Voss. He is Awesome.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by