Excel sheet work in specific column

1 visualización (últimos 30 días)
MINATI PATRA
MINATI PATRA el 26 de Dic. de 2023
Comentada: MINATI PATRA el 27 de Dic. de 2023
status = mkdir('D:\PK7\kpk'); cd D:\PK7\kpk
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(:)]
writematrix(output, 'PriyaSRM11.xlsx','Sheet', 'Results');
%% I want to save the output in specific columns of the Excel sheet, say, First column output in A1:A3, Second in B4:B6, and third in C7:C9
  2 comentarios
Dyuman Joshi
Dyuman Joshi el 26 de Dic. de 2023
It can be done, but it won't be a good idea as you will problems while reading the data.
Any particular reason why you want to do this?
MINATI PATRA
MINATI PATRA el 26 de Dic. de 2023
Actually this will be helpful for long data

Iniciar sesión para comentar.

Respuesta aceptada

Dyuman Joshi
Dyuman Joshi el 26 de Dic. de 2023
Well, here's a way -
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(:)]
output = 3×3
-1.1266 0.5060 -0.3373 -1.1557 0.5039 -0.3359 -1.2112 0.4997 -0.3331
%Run a for loop through the columns of output
for k=1:size(output,2)
%Generate the range to save the data
str = sprintf('%s%d:%s%d', 64+k, 3*(k-1)+1, 64+k, 3*k)
%Save data via writematrix() specifying range
writematrix(output(:,k), 'PriyaSRM11.xlsx', 'Sheet', 'Results', 'Range', str)
end
str = 'A1:A3'
str = 'B4:B6'
str = 'C7:C9'
%Check the contents of the file
readcell('PriyaSRM11.xlsx', 'Sheet', 'Results')
ans = 9×3 cell array
{[ -1.1266]} {[<missing>]} {[<missing>]} {[ -1.1557]} {[<missing>]} {[<missing>]} {[ -1.2112]} {[<missing>]} {[<missing>]} {[<missing>]} {[ 0.5060]} {[<missing>]} {[<missing>]} {[ 0.5039]} {[<missing>]} {[<missing>]} {[ 0.4997]} {[<missing>]} {[<missing>]} {[<missing>]} {[ -0.3373]} {[<missing>]} {[<missing>]} {[ -0.3359]} {[<missing>]} {[<missing>]} {[ -0.3331]}
  5 comentarios
Dyuman Joshi
Dyuman Joshi el 27 de Dic. de 2023
Concatenate the outputs in a single matrix and call the readmatrix() directly.
As I mentioned, there's no need to specify range if you want to store data serially.
MINATI PATRA
MINATI PATRA el 27 de Dic. de 2023
ok
Thank you Dyuman

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by