How can I make a movie with one multidimensional matrix in MATLAB

조회 수: 7 (최근 30일)
yogan sganzerla
yogan sganzerla 2017년 9월 28일
편집: OCDER 2017년 9월 29일
Hello, I have a multidimensional matrix in MatLab -> T(41,41,501) and I would like to memorize all this matrix in a movie. What should I do?
I read that the function is VideoWriter but I couldn't make the video. I am attaching the matrix.
cheers.

채택된 답변

OCDER
OCDER 2017년 9월 28일
VidObj = VideoWriter('movie.avi', 'Uncompressed AVI'); %set your file name and video compression
VidObj.FrameRate = 30; %set your frame rate
open(VidObj);
for f = 1:size(T, 3)
writeVideo(VidObj, T(:, :, f));
end
close(VidObj);
  댓글 수: 4
yogan sganzerla
yogan sganzerla 2017년 9월 29일
편집: yogan sganzerla 2017년 9월 29일
Perfect Donald, It worked very well. I am adding a new version of the code to show how it is working now. The movie is playing just the last position of the matrix. Why it's happening? Cheers
OCDER
OCDER 2017년 9월 29일
편집: OCDER 2017년 9월 29일
It's only saving the current figure, and not all figures.
set(gca,'nextplot','replacechildren');
for f = 1:size(T,3)
frame = getframe(gcf); %Only saving one figure, regardless of frame f
writeVideo(VidObj,frame);
end
close(VidObj);
Are you plotting T somewhere and then saving a plot of T(:, :, f)? If so, you need to plot inside the for loop. If you want to save T only after normalizing, use this:
T = T / max(T(:));
VidObj = VideoWriter('movie.avi', 'Uncompressed AVI'); %set your file name and video compression
VidObj.FrameRate = 30; %set your frame rate
open(VidObj);
for f = 1:size(T,3)
writeVideo(VidObj, T(:, :, f));
end
close(VidObj);

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

추가 답변 (0개)

제품

Community Treasure Hunt

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

Start Hunting!

Translated by