Borrar filtros
Borrar filtros

matlab loop code to save figures

1 visualización (últimos 30 días)
Benjamin
Benjamin el 7 de Nov. de 2018
Comentada: Jan el 8 de Nov. de 2018
I have the code below. It works fine. Notice the filename. It starts with dr_1e-1. I have other files that go up to dr_1e-9. Is there a way to make my code loop through and create all of my figures or do I have to manually change it? Note that the title would need to change too.
fname='dr_1e-2_epax_1e-11_A1_OFF_A2_OFF.txt';
name = 'dr = 1e-7 - epax[0] = 1e-10 - A1 = OFF - A2 = OFF';
delimiterIn = ' ';
headerlinesIn = 5;
% Import the data file for post-processing
matrix = importdata(fname,delimiterIn,headerlinesIn);
A = matrix.data;
%Define the number of distinct isotherms
temp_ids = sum(A(:) == 0.2);
%Define the number of density points sampled
density_ids = length(A)/temp_ids;
%Grab density matrix
density = A((1:density_ids),1);
%Grab temperature matrix
pressure = A(:,3);
%Reshape temperature matrix so it has one column for each temperature
%(isotherm), rather than just a single long column
pressure = reshape(pressure,[density_ids,temp_ids]);
%Differentiate
%dPdD = gradient(pressure(:,1)) / gradient(density);
[~,dPdD] = gradient(pressure, mean(diff(density)));
[~,ddPddD] = gradient(dPdD, mean(diff(density)));
figure(1)
plot(density, ddPddD)
grid on;
ylim([-0.2 0.5])
xlim([0.4 0.68])
xlabel('\rho (g/cm^3)');
ylabel('\partial^2p/\partial\rho^2')
suptitle(name)
saveas(gcf,name)
  1 comentario
Jan
Jan el 8 de Nov. de 2018
"It starts with dr_1e-1" - I see the variable fname starting with 'dr_1e-2'.

Iniciar sesión para comentar.

Respuestas (1)

Jan
Jan el 8 de Nov. de 2018
I guess all you need is
for k = 1:9
fname = sprintf('dr_1e%d-2_epax_1e-11_A1_OFF_A2_OFF.txt', k);
...
end
It is not clear what you have to change in the code.

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by