Plotting multiple times in a function

5 次查看(过去 30 天)
Hi , I amd new using matlab and I would want to know how can I plot every generation of child ( xh) and see how has improve each generation in each iteration of jj. Total of generations are 200.
Code is below.
clear all
close all
clc
f = @(x,y) x*exp(-x^2 -y^2);
Ge = 200; %generations
N = 50;
D = 2;
xl = [-2 ; -2];
xu = [2 ; 2];
aptitud = zeros(1,N);
x = zeros(2,N); %parents
for i=1:N
x(:,i) = xl+(xu - xl).*rand(2,1);
end
for jj=1:Ge
for i=1:N
fx = f(x(1,i),x(2,i));
if fx >= 0
aptitud(i) = 1/(1+fx);
else
aptitud(i) = 1+abs(fx);
end
end
xh = zeros(2,N); % children
for k=1:2:N
p1 = seleccion(aptitud);
p2 = p1;
while p2 == p1
p2 = seleccion(aptitud);
end
[h1,h2] = cruza(x(:,p1),x(:,p2));
xh(:,k) = h1;
xh(:,k+1) = h2;
end
% disp(xh);
pm = 0.3;
for i=1:N
for j=1:D
if rand > pm
else
xh(j,i) = xl(j) + (xu(j) - xl(j))*rand();
end
end
end
x = xh;
end
  1 个评论
Yasasvi Harish Kumar
Use the plot command to plot.
Syntax: plot(x,y)
Use the hold on command after the plot command to plot over the previous plot or use subplot command to have multiple plots.
Regards

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Genetic Algorithm 的更多信息

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by