Mechy
Mechy

Reputation: 259

How to make a video from a 3d matrix in matlab

I have a whole bunch of 2D matrices in matlab (they're suppose to make up a 3D matrix where the 3rd dimension is time), and I'm trying to make a video from the image data.

I know that I can use surf() to make a surface plot using one of the 2D matrices, but I'm not sure which command to invoke to take all my 2D matrices and convert them into a video of the surface plot.

Can anyone help?

Upvotes: 5

Views: 8414

Answers (1)

tmpearce
tmpearce

Reputation: 12693

The built-in function immovie(X,map) is one option for what you want. This function expects a m-by-n-by-1-by-k 4D matrix, where the 4th dimension is the frames of the movie. Since you're starting with a 3D matrix, use permute first:

Orig; % 3D matrix
X = permute(Orig,[1 2 4 3]); % 4D matrix
movie = immovie(X,map); % map is the colormap you want to use

implay(movie);

Upvotes: 7

Related Questions