Plot animation Effcientcey and double to struct error
1 view (last 30 days)
Show older comments
Lawson Hoover on 8 Dec 2012
I am trying to animate a plot. I have got it to work but I seems to moving a tad slow, and Also when I allocate the frames into a variable M with getframe, the M gets a red underline saying that I should preallocate for speed. I have been trying to do this but I get is the error:
The following error occurred converting from struct to double:
Error using double
Conversion to double from struct is not possible.
I have no idea how to fix this. The code I am using is below:
plot(x,y,'--r','LineWidth',3); % original position
xlabel('Beam Length (in.)','Color','g');
z = 0;
M = zeros(1,100);
ht = plot(y,z,'-b','linewidth',2); % new position
for i = 1:100
if i == 1
M(i) = getframe(gcf); % this says that I shoudld preallocate it but when I do I get an error
legend('Without Deflection','With Deflection');
Walter Roberson on 8 Dec 2012
getframe() returns a movie frame, which is a struct. You cannot store a struct into a scalar double location such as M(i) where M has been initialized to zeros(1,100)
What are you going to do with the frames after you get them? If you are going to create a video, then see the documentation for VideoWriter for an example of how to do it.
Find more on Animation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!