Is there a way to save snapshots of figures in a LiveScript without keeping the figure objectss open in a for loop?
조회 수: 6 (최근 30일)
이전 댓글 표시
I have a plotting function in a for loop to go through data and produce a plot for each of them. Let's say the resultant figure contains huge amount of graphic objects, and very heavy in memory.
for i = 1:20
figure
plot(rand(10,1),rand(10,1))
end
In such cases, it would be useful, if one can keep only the screenshots of figures in a Live Script without keeping the bulky invisible figure objects open.
Hypothetically, if the code below could allow you to save snapshots in a Live Script, without actually keeping the figure object active, that might be convinient. The problem is that the code below will just close all the figures and nothing is shown in a Live Script.
for i = 1:20
figure
plot(rand(10,1),rand(10,1))
drawnow
close
end
This is the closest I could found. Actual plotting is postponed until the for loop finishses. But still the invisible figure objects are accumulating during the for loop.
for i = 1:20
figure
plot(rand(10,1),rand(10,1))
drawnow limitrate
end
drawnow
close all
Does anyone know to if keeping snapshots in a LiveScript without keeping figure objects is possible?
댓글 수: 0
채택된 답변
Fangjun Jiang
2020년 3월 9일
편집: Fangjun Jiang
2020년 3월 10일
use saveas() to save the figure image.
test1.mlx, file size is 753k. 20 figures are saved. Each contains individual figure objectives.
for k=1:20
h=figure;
plot(rand(3));
end
test2.mlx, file size is 666k. 20 figures are saved but each is an image.
for k=1:20
h=figure;
plot(rand(3));
saveas(h,'test.png');
imshow('test.png');
end
When your data is really large and complex, maybe the .mlx file with image could be much smaller.
댓글 수: 3
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!