0

I want to plot the sphere function as a surface or a contour plot, and the position and fitness value of the best individual which are evaluated by a sphere function of data generated from a Gaussian distribution superimposed with it. The plot will change in each generation so i get a movie. Also, on another figure, i want to plot the contour of the sphere function superimposed with the entire population generated from Gaussian distribution, with the retained fit individuals colored in red. This from generation to generation should give another movie.

This is basically an implementation of estimation of distribution algorithm(EDA). Anyone know how to do this?

EDIT

K= 4 
for l = 1 : K 
contour(X,Y,ph); 
hold on 
plot(bestId, 'rx'); 
end 

The above code should superimpose contour plot and BestId. For each loop of l, a bestId is generated and superimposed with the contour plot. This generation of BestInd should take place for each l. but among the generations of bestId from 1 to 4, there is one which is the best of them and we should get that after four generation which is superimposed with the contour plot. Now i want this generation to be a movie for reach iteration from 1 to 4, so that i can see how the bestId are generated untill the best(optimal) one is achieved. this is what i meant by movie in matlab. Any idea on how this could be done?

user2179716
  • 79
  • 1
  • 9
  • I have no knowledge about what you want to do, but I know that you can capture figure frames into a video file. I suggest you to take a look at [`VideoWriter`](http://www.mathworks.com/help/matlab/ref/videowriterclass.html) (ecpecially the final self explanatory example) and [`getframe`](http://www.mathworks.com/help/matlab/ref/getframe.html). – p8me May 30 '13 at 02:18
  • @pm89 thanks for your reply. Do you know about Estimation of Distribution Algorithm (EDA)? I am trying to understand it by implementing it. – user2179716 May 30 '13 at 02:28
  • @user2179716: I think `VideoWriter` will probably work for you. Please read the StackOverflow [FAQ](http://stackoverflow.com/faq) about [asking reasonably-scoped, specific questions](http://stackoverflow.com/faq#dontask) (one at a time is good too). – horchler May 30 '13 at 03:12
  • @user2179716, I googled and this came along: [MATEDA](http://www.sc.ehu.es/ccwbayes/members/rsantana/software/matlab/MATEDA.html). Maybe it could help you. – Mahm00d May 30 '13 at 06:58
  • @Mahm00d, I have looked at MATEDA already but kind of complicated to understand, so i decided to try and implement myself for understanding. – user2179716 May 30 '13 at 11:18
  • @horchler have you people abandon me in this question? Please i need help. I completely don't know how to go about with this. – user2179716 Jun 01 '13 at 02:44
  • I think you need to ask a new question. Provide the code for what you have tried in order to generate a basic movie (maybe start from the ["AVI File from Animation" example here](http://www.mathworks.com/help/matlab/ref/videowriterclass.html#example_2)). Describe what doesn't work or what you don't understand. Describe what behavior or output you expect. Don't go into technical details about EDA, etc. if the the question is about producing a video. Also, make sure that you want a movie, as opposed to an animation - [see this](http://www.mathworks.com/help/matlab/creating_plots/animation.html). – horchler Jun 01 '13 at 17:52

1 Answers1

1

To create movie reflecting changes in figures, I am using combination of the class avifile and functions getframe() and addframe()

Here is an example

aviobj = avifile('example.avi','compression','None');

t = linspace(0,2.5*pi,40);
fact = 10*sin(t);
fig=figure;
[x,y,z] = peaks;
for k=1:length(fact)
    h = surf(x,y,fact(k)*z);
    axis([-3 3 -3 3 -80 80])
    axis off
    caxis([-90 90])

    F = getframe(fig);
    aviobj = addframe(aviobj,F);
end
close(fig);
aviobj = close(aviobj);

You can find more info here

http://www.mathworks.nl/help/matlab/ref/avifile.html

http://www.mathworks.nl/help/matlab/ref/movie.html

http://www.math.canterbury.ac.nz/~c.scarrott/MATLAB_Movies/movies.html

-----------------Edit after the discussion in the comments------------------

pm89 suggested another way in the comments. The VideoWriter class seems more modern and up to date. The example of use can be found at the end of the page below

http://www.mathworks.nl/help/matlab/ref/videowriterclass.html

Community
  • 1
  • 1
freude
  • 3,632
  • 3
  • 32
  • 51
  • I would still suggest [`VideoWriter`](http://www.mathworks.com/help/matlab/ref/videowriterclass.html) since [`avifile`](http://www.mathworks.com/help/matlab/ref/avifile.html) is going to be removed after 2013a. – p8me May 30 '13 at 12:42
  • I did know that. In this case, you are right. I have just shown what I get used to use – freude May 30 '13 at 12:48
  • So with some piece of code that has a loop, the data on the plot should change each time the loop runs, with this we can have some sort of a movie. Will the above suggestion achieve the goal? we can move to chat for more details – user2179716 May 30 '13 at 13:31
  • Yes, it will. You can find an example titled "AVI File from Animation" at the end of the page http://www.mathworks.nl/help/matlab/ref/videowriterclass.html – freude May 30 '13 at 13:42
  • If you don't want to save the frame each loop iteration, you can insert a condition inside the loop, which allow you to save frames for some defined values of the counter – freude May 30 '13 at 13:44
  • @freude,Lets say you have this part of code which is also inside a bigger for loop. K= 4 for l = 1 : K subplot(1,2,1); contour(X1,X2,ph); hold on plot(bestId, 'rx'); end How can you create a movie on this. Each time the loop goes, we have different position of the bestId superimposed with the contour plot, thus having a movie. How can this be achieve? Can you modify it to do what we expecting? – user2179716 May 30 '13 at 15:19
  • You can do essentially the same as in previous examples. To deal only with one subplot, you have to return a handle to it doing this: h=subplot(1,2,1) Than you plot your plots and do F = getframe(h); – freude May 31 '13 at 07:27
  • @freude can you please edit my code above and do what you are saying here on it and let em see. I am trying to follow what you said here, but it not coming. Maybe i miss understand you. – user2179716 May 31 '13 at 10:32
  • @freude i still need your help. I still have no idea in solving this – user2179716 Jun 01 '13 at 02:45
  • I did what I could. My knowledge is not enough to give you more info – freude Jun 01 '13 at 15:07
  • @freude is my question clear? Did i make my problem very clear? or you just don't have a clue of it? – user2179716 Jun 01 '13 at 15:39