load .mat files into a loop
Mostrar comentarios más antiguos
Good morning!
I have extracted CoTiVGa0.mat, CoTiVGa01.mat, CoTiVGa02.mat ... etc arrays from a previous excel document, and I would like to load them into my script as a loop in order to save the variables minpts, moment, dmdv, Tc and dTcdv into a single vector for several docs. Hope you can help me.
Regards,
Miguel Cardoso
lattice=CoTiVGa0(:,1);
totalenergy_PBE=CoTiVGa0(:,2);
moment=CoTiVGa0(:,3);
Tc=CoTiVGa0(:,4);
polynomialcoefficients_PBE=polyfit(lattice,totalenergy_PBE,3);
linearfunction=linspace(min(lattice)-0.01*min(lattice),max(lattice)+0.01*max(lattice),1000);
d1p = polyder(polynomialcoefficients_PBE); % First Derivative
d2p = polyder(d1p); % Second Derivative
ips = roots(d1p); % Inflection Points
xtr = polyval(d2p, ips); % Evaluate ?d2p? at ?ips?
minpts = ips((xtr > 0) & (imag(xtr)==0)); % Find Minima
energyfit_PBE=polyval(polynomialcoefficients_PBE,linearfunction);
plot(lattice,totalenergy_PBE,'o',linearfunction,energyfit_PBE,'k',minpts,polyval(polynomialcoefficients_PBE,minpts),'or');
xlabel('Lattice Paramenter (\AA)','Interpreter','Latex')
ylabel(' Total Energy (eV)','Interpreter', 'Latex')
legend('SPR-KKR data','Polynomial fit',strcat('Optimized Lattice Parameter(' , num2str(minpts), '\AA)'),'Interpreter','Latex');
axis('tight');
% https://www.mathworks.com/matlabcentral/answers/165219-how-can-i-make-function-and-find-minimum
% Derivatives
moment=CoTiVGa0(:,3);
Tc=CoTiVGa0(:,4);
a1=max(lattice(lattice<minpts));
b1=min(lattice(lattice>minpts));
a2=find(lattice==a1);
b2=find(lattice==b1);
m_a=moment(a2);
m_b=moment(b2);
dmdv=(m_b-m_a)/(b1^3-a1^3); % Needs to be checked
Tc_a=Tc(a2);
Tc_b=Tc(b2);
dTcdv=(Tc(b2)-Tc(a2))/(b1^3-a1^3);
% Magnetic moment and Tc of minpts
Tc_coefs=polyfit(lattice,Tc,1);
Tc_min=Tc_coefs(1)*minpts+Tc_coefs(2);
moment_coefs=polyfit(lattice,moment,1);
moment_min=moment_coefs(1)*minpts+moment_coefs(2);
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!