필터 지우기
필터 지우기

matlab loop code to save figures

조회 수: 1 (최근 30일)
Benjamin
Benjamin 2018년 11월 7일
댓글: Jan 2018년 11월 8일
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
Jan
Jan 2018년 11월 8일
"It starts with dr_1e-1" - I see the variable fname starting with 'dr_1e-2'.

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2018년 11월 8일
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.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by