Rotate 3D plot in PowerPoint

I want to be able to rotate a 3D plot in powerpoint. I found a few exchange files that rotate a plot and save it as a gif, but the problem with that is they use a loop to rotate the image. My figure is complicated, and I do not know what angles I need to rotate through without looking. Put more simply, is there a way to rotate a plot using the hand tool and record an animation of that? (any movie type will do, I can convert it to something PowerPoint can use after I've made it). I realize that may be a tall order.
Alternatively, if there is a way to put an interactive plot in powerpoint (the computer used will have MATLAB installed) that would work too.
Thanks

2 Comments

you could also:
  1. save your figure as MATLAB fig file
  2. write one line matlab function that loads this *.fig file
  3. compile this function using Application compiler as a stand alone *.exe application
  4. insert the standalone *.exe file *as a link* (to avoid blocking do not insert as an object) into power point
  5. during presentation you will have full matlab control of the figure
I really appreciate dmitry's suggestion.

Sign in to comment.

 Accepted Answer

Sean de Wolski
Sean de Wolski on 11 Jan 2013
Edited: Sean de Wolski on 11 Jan 2013
Thanks for giving my brain one last challenge before I shut it off for the week!
Here is something that seems to work. It starts a timer that gives you x amount of time to rotate the plot. It is recording the rotation. You can then feed the recording into the second function that plays it. Obviously, a lot of numbers here are hardwired (0.5, 500) etc. Right now you get 25 seconds at a frame rate of 20fps.
To record it:
function V2 = RecordRotation
surf(peaks);
n = 500;
V = zeros(n,2);
T = timer('period',0.05,'executionmode','fixedrate',...
'TimerFcn',@captureAzEl,'TasksToExecute',n);
rotate3d on
drawnow;
start(T);
drawnow;
wait(T);
V2 = V;
function captureAzEl(src,~)
cnt = get(src,'TasksExecuted');
[V(cnt,1), V(cnt,2)] = view;
drawnow;
end
end
And to play it:
function playRecording(V)
frame_period = 0.05;
n = length(V);
T = timer('period',frame_period,'executionmode','fixedrate',...
'TimerFcn',@playRecording,'TasksToExecute',n);
rotate3d on
drawnow;
start(T);
drawnow;
wait(T);
function playRecording(src,~)
cnt = get(src,'TasksExecuted');
view(V(cnt,1), V(cnt,2));
drawnow;
end
end
And then to run the whole thing:
v = RecordRotation;
playRecording(v);
Once the figure appears, you immediately have 25 seconds. After that, it regains control and tells it how to rotate.
Next week I'll polish this up with comments etc.

4 Comments

Thanks, this works very well.
Now how can I record the playback? This code will save frames as a .gif,
x = 0:0.01:1;
figure(1)
filename = 'testnew51.gif';
for n = 1:0.5:5
y = x.^n;
plot(x,y)
drawnow
frame = getframe(1);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);
if n == 1;
imwrite(imind,cm,filename,'gif', 'Loopcount',inf);
else
imwrite(imind,cm,filename,'gif','WriteMode','append');
end
end
but it uses a for loop with n steps. I can't figure out how to access the step that the timer is currently on
That's why I don't recommend doing the getframe in real time. Once you have the V vector above (from my code), you can then:
  1. loop down it; (similar to playRecording)
  2. drawnow;
  3. getframe
  4. save the image.
This will be completely independent of time and user interaction.
function playRecording(RecordRotation)
filename = 'Compare data to MC fits.gif';
for i = 1:length(RecordRotation)
view(RecordRotation(i,1), RecordRotation(i,2));
drawnow;
frame = getframe(gcf);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);
if i == 1;
imwrite(imind,cm,filename,'gif', 'Loopcount',inf);
else
imwrite(imind,cm,filename,'gif','WriteMode','append','DelayTime',0.03);
end
end
I'll take a loot at this later today.

Sign in to comment.

More Answers (1)

Shibo Zou
Shibo Zou on 17 Feb 2017
Edited: Shibo Zou on 17 Feb 2017
For those who come here to find ways to embed a real interactive 3D plot instead of just a gif in PowerPoint,
Please look at this script which helps embed a real interactive 3D plot in PDF. I suggest you convert your PowerPoint to PDF for presentation. Because the interactive 3D plot won't work if you transfer or embed the PDF in PowerPoint.

Categories

Community Treasure Hunt

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

Start Hunting!