相关疑难解决方法(0)

在内存中渲染MATLAB图

是否有任何替代方法可以使用getframesaveas将图形内容保存到光栅图像中以进行进一步处理?

方法1: getframe

h = figure('visible', 'off');
a = axes('parent', h);

% render using `scatter3()` or other plot function.

content = frame2im(getframe(h));
Run Code Online (Sandbox Code Playgroud)

这具有显示图形在调用中执行屏幕捕获的严重缺点,getframe()并且当在循环中执行这样的渲染时(即,content在每次迭代时将其保存为视频帧)存在问题.

方法2: saveas

h = figure('visible', 'off');
a = axes('parent', h);

% render using `scatter3()` or other plot function.

saveas(h, '/path/to/file.png');
content = imread(/path/to/file.png');
Run Code Online (Sandbox Code Playgroud)

这种方法具有写入磁盘的严重缺点,这在多线程应用程序中存在问题,并且比直接渲染到内存要慢.因为saveas()在调用PNG编码器之前显然会渲染到内存,所以我想要的是可能的,但我在MATLAB文档中找不到任何只执行渲染部分的函数.

问题:

您是否知道将任意axes内容渲染到光栅图像的替代方法?

video matlab image screen-capture off-screen

24
推荐指数
3
解决办法
1万
查看次数

在MATLAB中创建电影文件的问题

我试图通过循环遍历MATLAB中的帧来创建一部电影.

请参阅http://www.mathworks.com/help/techdoc/ref/movie.html上的mathworks.com文档,我设法为一个情节设置动画.但是,当我尝试将电影保存在avi文件中时会出现问题.

/sf/answers/562697831/中avifileVideoWriter方法都导致了相同的错误.

虽然动画运行正常,但保存的影片只包含一个固定的帧,有时屏幕截图包含我的后台Web浏览器的叠加层.

先感谢您.

下面是我使用的代码,avi上冻结的框架链接如下.

Z = peaks; surf(Z); 
axis tight
set(gca,'nextplot','replacechildren');

vid = VideoWriter('myPeaks2.avi');
vid.Quality = 100;
vid.FrameRate = 15;
open(vid);
for k = 1:20 
    surf(sin(2*pi*k/20)*Z,Z)
    writeVideo(vid, getframe(gcf));
end
close(vid);

winopen('myPeaks2.avi')
Run Code Online (Sandbox Code Playgroud)

在avi上冻结的框架在下面链接

video matlab animation

6
推荐指数
2
解决办法
2万
查看次数

随时间执行循环

我有这样的for循环

for t = 0: 1: 60
    // my code
end
Run Code Online (Sandbox Code Playgroud)

我想在第1,第2,第3,......,第60秒执行我的代码.这该怎么做?另外我如何在任意时间运行我的代码?例如在第1秒,第3秒和第10秒?

matlab for-loop timer

3
推荐指数
2
解决办法
3606
查看次数

标签 统计

matlab ×3

video ×2

animation ×1

for-loop ×1

image ×1

off-screen ×1

screen-capture ×1

timer ×1