how to plot minimized fitness function at y-axes and set its range with generation number at y-axes in matlab

To plot a minimized fitness function at the y-axis and set its range with the generation number at the x-axis in MATLAB, you can follow these steps:

  1. Generate the fitness values and generation numbers as vectors.
  2. Specify the range for the y-axis using the ylim function.
  3. Create a plot using the plot function with the generation numbers on the x-axis and the fitness function values on the y-axis.

Here is an example code snippet that demonstrates this process:

main.m
% Generate sample fitness values and generation numbers
fitness = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1];
generations = 1:length(fitness);

% Set the y-axis range
yMin = min(fitness);
yMax = max(fitness);
ylim([yMin, yMax]);

% Plot the fitness function values
plot(generations, fitness);

% Add labels and title
xlabel('Generation Number');
ylabel('Fitness Function');
title('Minimized Fitness Function Plot');
405 chars
17 lines

Make sure to replace fitness and generations with your actual data.

This code will plot the fitness function values on the y-axis, with the range of the y-axis set based on the minimum and maximum fitness values. The x-axis will show the corresponding generation numbers.

Note: Make sure you have MATLAB installed on your system to run this code.

gistlibby LogSnag