I need to save a value stored in a variable in a matlab function in a separate Excel file
3 views (last 30 days)
Show older comments
I have a MATLAB code that has three four functions to solve a couple partial differential equation system. I need to find a way to save the values stored in a particular variable in a separate excel file. I need to save the values of (Ke)*DuDx(1)/g in line 63 and (u(1)-u(2) in line 64 in separate variables and obtain them as output so that I can save them in separate excel files.
The code is given below
function pde_TwoTemperature_solve
% pde_TwoTemperture_solve
clear
format long
m =0;
x=0:10e-10:50e-9;
t=0:100e-15:1e-12;
%%---------------------------------
[sol] = pdepe(m,@pdex5pde,@pdex5ic,@pdex5bc,x,t);
Te = sol(:,:,1);
Tp = sol(:,:,2);
save('electron_temperature.mat','Te')
save('phonon_temperature.mat','Tp')
figure
surf(x,t,sol(:,:,1))
title('Electron Temperature')
xlabel('Space')
ylabel('Time')
zlabel('Temperature')
figure
surf(x,t,sol(:,:,2))
title('Phonon Temperature')
xlabel('Space')
ylabel('Time')
zlabel('Temperature')
% --------------------------------------------------------------------------
function [c,f,s,d] = pdex5pde(x,t,u,DuDx)
%function [c,f,s,uMinusV,KeDuDx] = pdex5pde(x,t,u,DuDx)
%------------Au-----------
g=1e17;
rho=8.96e3;
Ce=96.8;
Ci=3.62e6;
delta=15.3e-9;
tao=100e-15;
F=17;
alpha=398;
beta=0.16;
Tf=6.42e4;
tp=100e-15;
w0=650e-9;
tp=200e-15;
tee = 200e-15;
Ke=alpha*(u(1)/u(2));
Kl=7;
xx=500e-9;
dt=200e-15;
%S=(((0.49*F)/(delta*(tp+tee))) * (exp(-2.77 * (((t) - (2 * (tp + tee))) / (tp + tee))^2)));
S=(0.94*F/((tao*(delta+100e-9))*(exp(-x(end)/(delta+100e-9)))))*(exp((-x/(delta+100e-9))+(-2.77*((t/tao).^2))));;%Ë«Âö³åÌ弤¹âÔ´Ïî
%%%---------------%%%%%%%-------------------------
c = [Ce*u(1)/g; Ci/g];
f = [ (Ke)*DuDx(1)/g; (Kl)*DuDx(2)/g];
s1 = -(u(1)-u(2))+S/g;
s2 =(u(1)-u(2));
s = [s1; s2];
% --------------------------------------------------------------------------
function u0 = pdex5ic(x)
u0 = [300; 300];
% save u(1)-u(2) and (Ke)*DuDx(1)/g to separate arrays
% --------------------------------------------------------------------------
%function [pl,ql,pr,qr] = pdex5bc(xl,ul,xr,ur,t)
%hep = 5e9;
%hpp = 500e6;
%pl = [0; 0];
%ql = [1; 1];
%pr = [hep*(ur(1)-300); hpp*(ur(2)-300)];
%qr = [1; 1];
%------------------------------------------------------------------------------
function [pl,ql,pr,qr] = pdebc(xl,ul,xr,ur,t)
pl = [0;ul(1)];
ql = [300;300];
pr = [ur(1)-300;ur(2)];
qr = [300;300];
%[uMinusV, KeDuDx] = pdex5pde(x,t,sol(:,:,1),sol(:,:,2));
%dlmwrite('uMinusV.txt', uMinusV, 'delimiter', '\t');
%dlmwrite('KeDuDx.txt', KeDuDx, 'delimiter', '\t');
0 Comments
Answers (1)
Image Analyst
on 7 May 2023
You need to create your output inside the function then return it to the calling routine:
function output = pde_TwoTemperature_solve
If you want to save something in a file, there are lots of functions for that, like save(), writematrix(), fprintf(), etc.
2 Comments
Image Analyst
on 8 May 2023
I have no idea what's going on in this uncommented code. I have no idea which of those dozens of variables you consider to be the, or an, "output". Only you know that.
See Also
Categories
Find more on Environment and Settings 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!