views:

305

answers:

2

Hi,

I have a 3d histogram in matlab. Is it possible to automatically spin it i.e to get the 3d effects. I want to show it as a video in PowerPoint where the 3d histogram swivels.

thanks

+1  A: 

A somewhat cumbersome way to do this would be to rotate the chart manually using the view command. You can update azimuth and elevation views of any 3D plot using this command.

Creating a video of it requires capturing the plot window using a command sequence like this (note, you're going to get the gray background, so you might want to change the background color):

% create figure and get handle to it (store handle in hf)
hf = figure(1);

% [create 3d plot]

% Create file to hold the animation
aviobj = avifile('mymovie.avi', 'compression', 'Cinepak');

% loop with some criteria for rotation
while(...)
    % update view using view command
    view(az, el);

    % get Matlab to flush the drawing buffer (effectively forces a plot update)
    drawnow;

    % capture frame and write to the avi file
    aviobj = addframe(aviobj, hf);
end
% end loop

% Close movie (flushes write buffer and finishes the video)
aviobj = close(aviobj);

You can use the same tactic without the avifile stuff to rotate the plot using a script in Matlab, though you might want to use a pause command to slow down the frame change.

Mark E
A: 

Let us make sure we are talking about the same thing here. A 2-D histogram would have bins of a specified X and Y range and the count would be shown on a Z axis. A 3-D histogram would have bins in the X and Y and Z ranges with the count shown in some other way (color?) You would need slicing for a 3-D histogram to make sense.I am going to assume that you mean a 2-D histogram that looks like a bunch of blocks coming out of the ground.

I think you will be better served to make this 2-D histogram into an image, where each pixel represents a specific bin in X and Y and the color specifies the count in that bin. I think the motion will only confuse the data. Use image or imagesc or imshow for this. Also, I would recommend an intensity based colormap (>>colormap), like spring or winter. This make the differences more apparent. Turn on the colorbar (>>colorbar)

MatlabDoug

related questions