5

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?

Mechy
  • 259
  • 1
  • 4
  • 14

1 Answers1

7

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);
Adriaan
  • 17,741
  • 7
  • 42
  • 75
tmpearce
  • 12,523
  • 4
  • 42
  • 60
  • Wow, so then you can use immovie to do it just as easily as that? My matrix basically is a 4D matrix if I combine all the 3D matrices together (technically 3D if you count the data stored in the x&y coordinates that corresponds to height. – Mechy May 14 '13 at 04:02
  • 3
    Oh, if anyone else is wondering how I did it, I followed this website: http://www.mikesoltys.com/2012/02/26/tool-of-the-week-making-animations-in-matlab/ Also, you'll have to keep in mind that you'll have to set your axes with zlim([min,max]), xlim(same thing) ylim(same) in order for the video to come out right. It'll try to change sizes if you don't. Oh, and then you might need to change the camera as well with campos([x,y,z]) – Mechy May 14 '13 at 04:04