Plot size varies even when plotting in a loop

4 views (last 30 days)
Hello all,
I wrote a loop that reads a set of data files, makes a plot using the data in each file, exports the plot to a png file, and continues.
Since this is done in a loop using a counter, I expect the images saved in png format to be the same size and resolution. However, the images seem to be of different sizes/positions, so when I try to assemble the png files to produce a movie, the movie appears to flicker or jerk.
Here is the body of the loop. Any thoughts would be appreciated.
Thanks.
for it = 1: nt
data = dlmread([pathName0 timeList{it} '/' var '_planeXY.raw'], '', 2, 0);
x = data(:, 1);
y = data(:, 2);
z = data(:, 4);
t1 = num2str(t(it, 1)*1.0e03);
xlin = linspace(0, max(x), 300);
ylin = linspace(min(y), max(y), 300);
[X, Y] = meshgrid(xlin, ylin);
Z = griddata(x, y, z, X, Y, 'cubic');
h = figure();
colormap(jet);
grid off;
surf(xlin/1e-03, ylin/1e-03, Z, 'Edgecolor', 'none');
shading interp;
view(2);
cb = colorbar();
set(cb, 'ytick', [0 0.05 0.1 0.15 0.2]);
cbTitle = get(cb, 'Title');
set(cbTitle ,'String', varName);
caxis([0 0.2]);
ylabel('$r$ [mm]', 'Interpreter', 'latex', 'Fontname', 'Times', 'Fontsize', 40);
xlabel('$z$ [mm]', 'Interpreter', 'latex', 'Fontname', 'Times', 'Fontsize', 40);
title(['Time: ' t1 ' [ms]'], 'Fontname', 'Times', 'Fontsize', 40);
yticks([-30 -20 -10 0 10 20 30]);
xticks([0 10 20 30 40 50 60 70 80]);
ax = gca();
set(ax, 'Fontname', 'Times', 'Fontsize', 24);
axis([0 80 -35 35]);
print(h, '-dpng', [caseLES '/' timeList{it} '.png']);
close all;
end
  1 Comment
dpb
dpb on 20 Jan 2020
If you want a specific resolution, use the key -r on the command line followed by the desired resolution.

Sign in to comment.

Answers (1)

Prabhan Purwar
Prabhan Purwar on 23 Jan 2020

Tags

Products

Community Treasure Hunt

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

Start Hunting!