import and export of excel sheet work

3 次查看(过去 30 天)
Fr = .1; M = .2; Kp = 0.50; lambda = 0.1; Nr = 0.1; Pr = 7; Rd = 0.5; Nb = 0.5; Nt = 0.5; H = 0.01;
Ec = 0.01; Le = 2; Sr = 1; D = 0.5; n = 1; E = 0.5; Bi = 0.5; Slip = 0.1;
for M = [0.2 0.3 0.5]
ODE = @(x,y)[ y(2); y(3); - y(1)*y(3) + (1+Fr)*y(2)^2 + (M+Kp)*y(2) - lambda*( y(4) - Nr*y(6) );
y(5); -(Pr/(1+Rd))*( y(1)*y(5) + Nb*y(5)*y(7) + Nt*y(5)^2 + H*y(4) + Ec*y(3)^2 );
y(7); -Pr*Le*y(1)*y(7) - (Nt/Nb)*(-(Pr/(1+Rd))*(y(1)*y(5) + Nb*y(5)*y(7) + Nt*y(5)^2 + H*y(4) + Ec*y(3)^2)) + Le*Pr*Sr*(1 + D*y(4))^n *y(6)*exp(-E/(1 + D*y(4)))];
BC = @(ya,yb)[ya(1); ya(2)-1-Slip*ya(3); ya(5)+Bi*(1-ya(4)); ya(7)+(Nt/Nb)*ya(5); yb([2;4;6])]; xa = 0; xb = 6; x = linspace(xa,xb,101);
solinit = bvpinit(x,[0 1 0 1 0 1 0]); sol = bvp5c(ODE,BC,solinit); S = deval(sol,x);
f0 = deval(sol,0); Cf = f0(3);Nu = - (1+Rd)*f0(5); Sh = - f0(7);
disp([Cf Nu Sh])
end
Attached excel sheet shows some calculation by the present code which I want MATLAB to follow the inputs of all the parameters and excecute the calculations of "Cf, Nu and Sh" (FORMULA described in the code) (CALCULATIONS given in the last columns of excel sheet) DIRECTLY and create another excel sheet or matlab TABLE type something.
  2 个评论
Dyuman Joshi
Dyuman Joshi 2023-11-30
What is your question?
It's not clear to me what you want to do.
MINATI PATRA
MINATI PATRA 2023-11-30
Actually Excel sheet is prepared manually by running this code and typing the values one by one. I want to calculate last column of each table by taking values of all the parameters and then if possible overwrite that last column calculated values automatically.
Formula for Cf, Nu, Sh are given within the code.

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2023-11-30
OK, you seem to do that. The loop in the (horribly uncommented) code computes Cf, Nu, and Sh. To create another sheet you need to call writetable after the loop. And if you want those values for all 3 iterations, you're going to have to index them as arrays. Something like (untested):
Fr = .1; M = .2; Kp = 0.50; lambda = 0.1; Nr = 0.1; Pr = 7; Rd = 0.5; Nb = 0.5; Nt = 0.5; H = 0.01;
Ec = 0.01; Le = 2; Sr = 1; D = 0.5; n = 1; E = 0.5; Bi = 0.5; Slip = 0.1;
allM = [0.2 0.3 0.5];
for k = 1 : numel(allM)
M = allM(k); % Get the M for this iteration.
% MINATI's computations:
ODE = @(x,y)[ y(2); y(3); - y(1)*y(3) + (1+Fr)*y(2)^2 + (M+Kp)*y(2) - lambda*( y(4) - Nr*y(6) );
y(5); -(Pr/(1+Rd))*( y(1)*y(5) + Nb*y(5)*y(7) + Nt*y(5)^2 + H*y(4) + Ec*y(3)^2 );
y(7); -Pr*Le*y(1)*y(7) - (Nt/Nb)*(-(Pr/(1+Rd))*(y(1)*y(5) + Nb*y(5)*y(7) + Nt*y(5)^2 + H*y(4) + Ec*y(3)^2)) + Le*Pr*Sr*(1 + D*y(4))^n *y(6)*exp(-E/(1 + D*y(4)))];
BC = @(ya,yb)[ya(1); ya(2)-1-Slip*ya(3); ya(5)+Bi*(1-ya(4)); ya(7)+(Nt/Nb)*ya(5); yb([2;4;6])]; xa = 0; xb = 6; x = linspace(xa,xb,101);
solinit = bvpinit(x,[0 1 0 1 0 1 0]); sol = bvp5c(ODE,BC,solinit); S = deval(sol,x);
f0 = deval(sol,0);
% Save the values for this loop
Cf(k) = f0(3);
Nu(k) = - (1+Rd)*f0(5);
Sh(k) = - f0(7);
fprintf('for k = %d, Cf = %f, Nu = %f, Sh = %f.\n', Cf(k), Nu(k), Sh(k));
end
output = [Cf(:), Nu(:), Sh(:)]
writetable(output, excelFileName, 'Sheet', 'Results');
To learn other fundamental concepts, invest 2 hours of your time here:
  3 个评论
Image Analyst
Image Analyst 2023-11-30
You need to have quotes around it
writetable(output, 'PriyaSRM.xlsx', 'Sheet', 'Results');
otherwise it thinks you have a structure called PriyaSRM with a field called xlsx.
or else assign it to a variable and pass the variable into writetable
fullFileName = fullfile(pwd, 'PriyaSRM.xlsx')
writetable(output, fullFileName', 'Sheet', 'Results');
MINATI PATRA
MINATI PATRA 2023-12-1
编辑:MINATI PATRA 2023-12-1
Ok done, many many thanks
Can the output of "Cf" be pasted in G3:G5, "Nu" in H18:H20, and "Sh" in L35:L37 of the same excel sheet. And is it possible if I kept the attached excel sheet in a particular drive and ask matlab to overwrite the above mentioned places.
Thanks again

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Import from MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by